c++g++macportsg++4.8rootpy

Unrecognized Command Line Option '-stdlib=libc++' with MacPorts gcc48


Context

I'm trying to compile the package "root_numpy" which is a link between the scientific analysis software "root" and the python package "numpy". It's used as part of the root wrapper "rootpy". I get a g++ error when the following line is executed:

g++ -bundle -undefined dynamic_lookup -g -arch x86_64 -headerpad_max_install_names 
    -arch x86_64 build/temp.macosx-10.6-x86_64-2.7/root_numpy/src/_librootnumpy.o 
    -o build/lib.macosx-10.6-x86_64-2.7/root_numpy/_librootnumpy.so 
    -L/Users/bwells/bin/root/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d 
    -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread 
    -lpthread -Wl,-rpath,/Users/bwells/bin/root/lib -stdlib=libc++ -lm -ldl 
    -lTreePlayer
g++: error: unrecognized command line option '-stdlib=libc++'

The same problem occurs when I compile a "hello world" program with the flag:

dhcp-130-112:helloworld bwells$ g++ -stdlib=libc++ helloworld.cpp 
g++: error: unrecognized command line option '-stdlib=libc++'

Without that flag, it compiles fine:

dhcp-130-112:helloworld bwells$ g++ helloworld.cpp 
dhcp-130-112:helloworld bwells$ ls
a.out       helloworld.cpp

My compiler version is:

dhcp-130-112:helloworld bwells$ g++ --version
g++ (MacPorts gcc48 4.8.2_2) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

AKA the result of running sudo port install gcc48. My Mac OS version is 10.9.3. The code file "helloworld.cpp" is as you'd expect

dhcp-130-112:helloworld bwells$ cat helloworld.cpp 

#include <iostream>

int main(void)
{
    std::cout << "Hello world!" << std::endl;
    return 0;
}
dhcp-130-112:helloworld bwells$ 

Question: From everything I can gather on the internet, the "-stdlib=..." flag is a standard part of g++. Why do I get a g++ error when including it? How can I fix this?

Note: While manually executing the setup.py line without the problem flag works, and allows the full package to compile, I experience linking errors when I try to import the resulting package into python. I'm concerned that the g++ problem here is a symptom of a larger issue, which is why I'm trying to solve it directly.


Solution

  • -stdlib=libc++ is a Clang (not GCC) option and tells clang to use LLVM libc++ standard library (which is what Clang uses) rather than GNU libstdc++ (which is what GCC uses).

    Since you got linking errors, it seems likely that other packages you are using were compiled with clang and libc++, which is not ABI compatible with GCC's libstdc++ (except for some low-level stuff). So you'll need to compile the package with clang and libc++ as well. Apple's Xcode comes with clang (which is probably what you'd want to use for this), and MacPorts also supplies a number of clang distributions.