2

Can someone point to flags and setup changes required for one to compile C++0x code on a Eclipse CDT on mac please ?

mmmmmm
  • 32,227
  • 27
  • 88
  • 117
Ajeet Ganga
  • 8,353
  • 10
  • 56
  • 79

2 Answers2

6

To use C++0x in Eclipse CDT on OSX (in a managed make project):

  • Open the project properties
  • C/C++ Build
  • Settings
  • Change the "Command" field in "MacOS X C++ Linker" and in "GCC G++ Compiler" from g++ to c++ (before check that c++ is clang++ with "c++ --version" in a shell)
  • Add "-std=c++0x -stdlib=libc++" in the "Miscellaneous" parameters of "GCC G++ Compiler"
  • Add "-stdlib=libc++" in the MIscellaneous "Linker flags" parameters of "MacOS X C++ Linker"
  • Open the "Discovery options", select the "GCC C++ compile" change g++ to c++ and add -std=c++0x to the "Compiler invocation arguments"
  • Add "/usr/include/c++/v1" to the "includes" in "Paths and Symbols" in C/C++ General
Marco
  • 2,389
  • 2
  • 16
  • 19
  • Works like a charm, even the editor recognizes the types. I prefer this method over installing Gcc via MacPorts. – abenthy Jul 28 '12 at 10:33
  • Compile and run success, but eclipse have some error in the IDE when edit code. Method 'cbegin' could not be resolved test.cpp /test/src line 18 Semantic Error – user501836 Jan 21 '13 at 11:14
  • This is my code: std::vector v; v.push_back(1); v.push_back(2); v.cbegin(); – user501836 Jan 21 '13 at 11:15
  • With XCode 4.5.2 add /usr/lib/c++/v1 to the includes in "Paths and Symbols" in C/C++ General. You can use also -std=c++11 instead of -std=c++0x (check that clang is 4.1 with c++ --version) – Marco Jan 21 '13 at 18:55
3

The latest Apple gcc compiler is gcc 4.2 which does not support C+11 code. You need to install a gcc 4.6 - this can be done from source or there are some binaries at hpc this put the gcc in /usr/local/bin Then use that in the preferences fot the C++ compiler in eclipse.

Alternative for Lion and above Xcode 4.* includes clang the latest version of which doies much of C+11

If you want a later gcc macports (and fink and homebrew) have a later version as a port. As of July 2012 macports has 4.7.1 and a 4.8 beta. The package managers are often the easiest way to get complex compiled code onto your machine and they also have centrally compiled versions that will be downloaded by default.

mmmmmm
  • 32,227
  • 27
  • 88
  • 117