Unrecognized command line option '-stdlib=libc++ for certain root gcc combinations on MAC

Dear rooters,
I’m working on a MACBook, OSX V 10.8.5.

I’m trying to compile root and subsequently a program (see attached Makefile) against root.
I use various versions of gcc (installed via macports) and root.

I just compile root without any special configuration options

-use gcc 4.7
-compile root 5.34 with it
->compile the program against root works

-use gcc 4.8 or 4.9
-compile root 6.05.02 with it
-> compile the program against root gives following error:
c++: error: unrecognized command line option ‘-stdlib=libc++’

I think the compiler is new enough… Any idea why this is not working?

Kind regards and many thanks in advance,
Merijn
PS I dubbed the makefile Makefile.cc since otherwise I couldn’t attach it …
Makefile.cc (885 Bytes)

Hi,

Can you use clang? GCC on MacOS is becoming more and more difficult…

Cheers, Axel.

Dear Axel, thanks for your reply.

I’m working on OSX 10.8.5
I updated to XCode 5.1 and installed CommandLineTools for Mountain Lion.
I try to compile root-6.05.02

I’ve first installed clang3.5 via macports and made it active.
First switched gcc off and tried to compile root -> compilation errors
Switched apple gcc/gcc4.9 to active aside clang3.5 and tried to compile root -> compilation errors

I tried as well to compile clang myself using your script:
raw.githubusercontent.com/karie … r/clone.sh

I tried compiling it with apple gcc and gcc4.9 -> compilation errors
get multiple errors, some related to std libraty but also different.

Could you give me a combination of XCode, gcc or clang and root6 that should work on OSX 10.8.5?
And when I make Clang active, should I also keep a gcc active or put it to none?
Hope I don’t bother.
Kind regards,
Merijn

Begin of thread for compiling clang:
/Users/Merijn/PhD/Software/Clang/src/include/llvm/ADT/iterator_range.h:36:29: error: no member named ‘move’ in namespace ‘std’
: begin_iterator(std::move(begin_iterator)),
~~~~~^
/Users/Merijn/PhD/Software/Clang/src/include/llvm/ADT/iterator_range.h:37:27: error: no member named ‘move’ in namespace 'std’
end_iterator(std::move(end_iterator)) {}
~^
/Users/Merijn/PhD/Software/Clang/src/include/llvm/ADT/iterator_range.h:48:33: error: no member named ‘move’ in namespace 'std’
return iterator_range(std::move(x), std::move(y));
~^
/Users/Merijn/PhD/Software/Clang/src/include/llvm/ADT/iterator_range.h:52:33: error: no member named ‘move’ in namespace 'std’
return iterator_range(std::move(p.first), std::move(p.second));
~^
llvm[1]: Compiling BranchProbability.cpp for Debug+Asserts build
In file included from /Users/Merijn/PhD/Software/Clang/src/lib/Support/Allocator.cpp:14:
In file included from /Users/Merijn/PhD/Software/Clang/src/include/llvm/Support/Allocator.h:24:
In file included from /Users/Merijn/PhD/Software/Clang/src/include/llvm/ADT/SmallVector.h:20:
/Users/Merijn/PhD/Software/Clang/src/include/llvm/Support/MathExtras.h:21:10: fatal error: ‘type_traits’ file not found
#include <type_traits>
^
In file included from /Users/Merijn/PhD/Software/Clang/src/lib/Support/ARMBuildAttrs.cpp:11:
/Users/Merijn/PhD/Software/Clang/src/include/llvm/ADT/StringRef.h:343:14: error: no template named ‘enable_if’ in namespace ‘std’; didIn file included from you/Users/Merijn/PhD/Software/Clang/src/lib/Support/BranchProbability.cpp :mean15 :
’__gnu_cxx::__enable_if’?In file included from /Users/Merijn/PhD/Software/Clang/src/include/llvm/Support/Debug.h
:31:
In file included from /Users/Merijn/PhD/Software/Clang/src/include/llvm/Support/raw_ostream.h:17:
/Users/Merijn/PhD/Software/Clang/src/include/llvm/ADT/StringRef.h:343:14: error: no template named ‘enable_if’ in namespace ‘std’; did you typename std::enable_if<std::numeric_limits::is_signed, bool>::type
mean ‘__gnu_cxx::__enable_if’? ^
~

begin of thread for compiling root:
nclude/RWrap_libcpp_string_view.h:329:4: error: redefinition of ‘__find_first_of_ce’
__find_first_of_ce(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
^
/opt/local/libexec/llvm-3.5/bin/…/include/c++/v1/algorithm:1045:1: note: previous definition is here
__find_first_of_ce(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
^
In file included from /Users/Merijn/PhD/Software/root-6.05.02/core/metautils/src/TClassEdit.cxx:9:
In file included from include/TClassEdit.h:66:
In file included from include/RStringView.h:26:
include/RWrap_libcpp_string_view.h:342:4: error: redefinition of ‘__str_find’
__str_find(const _CharT *__p, _SizeT __sz,
^
/opt/local/libexec/llvm-3.5/bin/…/include/c++/v1/string:996:1: note: previous definition is here
__str_find(const _CharT *__p, _SizeT __sz,
^
In file included from /Users/Merijn/PhD/Software/root-6.05.02/core/metautils/src/TClassEdit.cxx:9:
In file included from include/TClassEdit.h:66:
In file included from include/RStringView.h:26:
include/RWrap_libcpp_string_view.h:355:4: warning: ‘__str_find’ is missing exception specification ‘noexcept’
__str_find(const _CharT *__p, _SizeT __sz,
^
/opt/local/libexec/llvm-3.5/bin/…/include/c++/v1/string:1009:1: note: previous declaration is here
__str_find(const _CharT *__p, _SizeT __sz,
^
In file included from /Users/Merijn/PhD/Software/root-6.05.02/core/metautils/src/TClassEdit.cxx:9:
In file included from include/TClassEdit.h:66:
In file included from include/RStringView.h:26:
include/RWrap_libcpp_string_view.h:355:4: error: redefinition of ‘__str_find’
__str_find(const _CharT *__p, _SizeT __sz,
^
/opt/local/libexec/llvm-3.5/bin/…/include/c++/v1/string:1009:1: note: previous definition is here
__str_find(const _CharT *__p, _SizeT __sz,
^
In file included from /Users/Merijn/PhD/Software/root-6.05.02/core/metautils/src/TClassEdit.cxx:9:
In file included from include/TClassEdit.h:66:
In file included from include/RStringView.h:26:
include/RWrap_libcpp_string_view.h:376:4: warning: ‘__str_rfind’ is missing exception specification ‘noexcept’
__str_rfind(const _CharT *__p, _SizeT __sz,
^
/opt/local/libexec/llvm-3.5/bin/…/include/c++/v1/string:1030:1: note: previous declaration is here
__str_rfind(const _CharT *__p, _SizeT __sz,
^
In file included from /Users/Merijn/PhD/Software/root-6.05.02/core/metautils/src/TClassEdit.cxx:9:
In file included from include/TClassEdit.h:66:
In file included from include/RStringView.h:26:
include/RWrap_libcpp_string_view.h:376:4: error: redefinition of ‘__str_rfind’
__str_rfind(const _CharT *__p, _SizeT __sz,
^
/opt/local/libexec/llvm-3.5/bin/…/include/c++/v1/string:1030:1: note: previous definition is here
__str_rfind(const _CharT *__p, _SizeT __sz,
^
In file included from /Users/Merijn/PhD/Software/root-6.05.02/core/metautils/src/TClassEdit.cxx:9:
In file included from include/TClassEdit.h:66:
In file included from include/RStringView.h:26:
include/RWrap_libcpp_string_view.h:395:4: warning: ‘__str_rfind’ is missing exception specification ‘noexcept’
__str_rfind(const _CharT *__p, _SizeT __sz,
^
/opt/local/libexec/llvm-3.5/bin/…/include/c++/v1/string:1049:1: note: previous declaration is here
__str_rfind(const _CharT *__p, _SizeT __sz,
^
In file included from /Users/Merijn/PhD/Software/root-6.05.02/core/metautils/src/TClassEdit.cxx:9:
In file included from include/TClassEdit.h:66:
In file included from include/RStringView.h:26:
include/RWrap_libcpp_string_view.h:395:4: error: redefinition of ‘__str_rfind’
__str_rfind(const _CharT *__p, _SizeT __sz,
^
/opt/local/libexec/llvm-3.5/bin/…/include/c++/v1/string:1049:1: note: previous definition is here
__str_rfind(const _CharT *__p, _SizeT __sz,
^
In file included from /Users/Merijn/PhD/Software/root-6.05.02/core/metautils/src/TClassEdit.cxx:9:
In file included from include/TClassEdit.h:66:
In file included from include/RStringView.h:26:
include/RWrap_libcpp_string_view.h:414:4: warning: ‘__str_find_first_of’ is missing exception specification ‘noexcept’
__str_find_first_of(const _CharT *__p, _SizeT __sz,
^
/opt/local/libexec/llvm-3.5/bin/…/include/c++/v1/string:1068:1: note: previous declaration is here
__str_find_first_of(const _CharT *__p, _SizeT __sz,
^
In file included from /Users/Merijn/PhD/Software/root-6.05.02/core/metautils/src/TClassEdit.cxx:9:
In file included from include/TClassEdit.h:66:
In file included from include/RStringView.h:26:
include/RWrap_libcpp_string_view.h:414:4: error: redefinition of ‘__str_find_first_of’
__str_find_first_of(const _CharT *__p, _SizeT __sz,

Hi,

do not build GCC nor clang, do not download GCC nor clang.

Simply install XCode (not just the command line tools), then in a terminal type xcode-select --install. That will give you XCode’s clang which is what you need.

Then you simply run ./configure or cmake …/src or similar, without giving platform or compiler or anything. This just works - unless traces of your previous clang etc get in the way.

Cheers, Axel.

Dear Axel
I tried this, and it seems all to be working, many thanks!
I have to say though that
xcode-select --install
is not working on my machine (maybe it is for a later version)?

Thanks again,
Merijn

To maybe be a bit more precise: I installed XCode. Didn’t subsequently did anything with it. It is found (for example by tying xcode-select --print-path ).

I just put gcc and clang to none using autoports. Then everything roles.

Thanks again and kind regards,
Merijn

Hi again,

I successfully comiled root and Fastjet now using clang.

I compiled a program against root as well successfully.
The small test program of fastjet also compiled and run successfully.
I want now to compile a program against fastjet and root, and strangely this fails. It seems like something in root messes up the linking against fastjet:
This works, compiles and the resulting program runs:

g++ short-example.cc -o short-example fastjet-config --cxxflags --libs --plugins -v

When I try to compile the same program against root as well (nothing from root is used or included though) the following happens:

g++ short-example.cc -o short-example fastjet-config --cxxflags --libs --plugins root-config --glibs
Undefined symbols for architecture x86_64:
“fastjet::sorted_by_pt(std::__1::vector<fastjet::PseudoJet, std::__1::allocatorfastjet::PseudoJet > const&)”, referenced from:
_main in short-example-c5d8dd.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I googled a lot on it. Some suggestions are that something in roog-config is screwing up the linker due to which fastjet isn’t found anymore.
Another makefile I have which compiles some code solely to root (using root-config --glibs etc) compiles smoothly.

Any idea what is going wrong? I used most recent versions of root and fastjet.
For completeness I give some output of compilation( with -v option) below

Cheers
Merijn
PS: again the above mentioned --install option did return error to me, unrecognized option.

root-config --glibs
-L/Users/Merijn/PhD/Software/root-6.05.02/lib -lGui -lCore -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lpthread -Wl,-rpath,/Users/Merijn/PhD/Software/root-6.05.02/lib -stdlib=libc++ -lm -ldl

fastjet-config --libs
-Wl,-rpath,/Users/Merijn/PhD/Software/fastjet-3.1.3/…/fastjet-install/lib -lm -L/Users/Merijn/PhD/Software/fastjet-3.1.3/…/fastjet-install/lib -lfastjettools -lfastjet

Users/Merijn/PhD/CastorCalibration_LED_2015/EvaluationIntercalibration/CMSTotemSoft|> g++ short-example.cc -o short-example fastjet-config --cxxflags --libs --plugins root-config --glibs -v
Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin12.6.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.8.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name short-example.cc -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 236.3 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/…/lib/clang/5.1 -I /Users/Merijn/PhD/Software/fastjet-3.1.3/…/fastjet-install/include -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/Merijn/PhD/CastorCalibration_LED_2015/EvaluationIntercalibration/CMSTotemSoft -ferror-limit 19 -fmessage-length 237 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.8.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /var/folders/30/yyttfm2x0wx7trs0_q25mny40000gn/T/short-example-ca91cd.o -x c++ short-example.cc
clang -cc1 version 5.1 based upon LLVM 3.4svn default target x86_64-apple-darwin12.6.0
ignoring nonexistent directory “/usr/include/c++/v1"
ignoring nonexistent directory “/usr/local/include”
#include “…” search starts here:
#include <…> search starts here:
/Users/Merijn/PhD/Software/fastjet-3.1.3/…/fastjet-install/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/…/lib/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/…/lib/clang/5.1/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
”/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.8.0 -o short-example -L/Users/Merijn/PhD/Software/fastjet-3.1.3/…/fastjet-install/lib -L/Users/Merijn/PhD/Software/root-6.05.02/lib /var/folders/30/yyttfm2x0wx7trs0_q25mny40000gn/T/short-example-ca91cd.o -rpath /Users/Merijn/PhD/Software/fastjet-3.1.3/…/fastjet-install/lib -lm -lfastjettools -lfastjet -lfastjetplugins -lsiscone_spherical -lsiscone -lGui -lCore -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lpthread -rpath /Users/Merijn/PhD/Software/root-6.05.02/lib -lm -ldl -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/…/lib/clang/5.1/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
“fastjet::sorted_by_pt(std::__1::vector<fastjet::PseudoJet, std::__1::allocatorfastjet::PseudoJet > const&)”, referenced from:
_main in short-example-ca91cd.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
/

Hi,

Don’t use g++ but clang to compile. clang uses the “right” standard library.

Cheers, Axel.

Upon looking deeper into the problem, the following was found to cause it.
Root investigates what options are availbable for compilation and picks the optimal set. It compiles itself with -pthread -stdlib=libc++ -std=c++11 -m64 on my machine (Mountain Lion with Xcode5.1).
As visible from root-config --cflags
When compiling fastjet, it picks a set of default options for compilation which are different. When we subsequently compile a program just against root or just against fastjet, things work smoothly. But compiling against fj and root at the same time naturally fails.
The solution is to first compile fastjet with the same flags as root compiled itself with. These can be set either in the make file of fastjet, or one just exports the flags as environmental variables in the shell
export CXXFLAGS=’-stdlib=libc++ -std=c++11 -m64’ prior to compilation.

Note that when compiling against root, root-config --cflags returns automatically the -stdlib=libc++ -std=c++11 -m64 options. For Fastjet, even when compiled with this flags, fastjet-config --cxxflags doesn’t return these. So after fastjet is compiled with these options and we compile a programs against fj, we must make sure to invoke these options or we still get inconsistencies.

Hope this is helpful, many thanks to Axel for his help on this!
PS: it seems that after mac upgraded to Mavericks, stdlib=libc++ became the standard so might not be necessary anymore