Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make clang search for gcc's headers?

I want to replace gcc with clang (3.3) to build my C++11 code, so I should use clang's option -stdlib=libstdc++ (to make it see STL headers). The option works: clang see headers like string, but can't find c++11 headers (type_traits) because clang searches in 4.2 directories:

clang++ -stdlib=libstdc++ -E -x c++ - -v < /dev/null
...
/usr/include/c++/4.2
/usr/include/c++/4.2/backward
/usr/include/clang/3.3
/usr/include
...

How to make it look at never versions of GCC's headers?

As far as I understand, only libc++ (not libstdc++) is supported by clang for C++11 so the only way it so install libc++?

like image 948
pavelkolodin Avatar asked Oct 12 '15 14:10

pavelkolodin


People also ask

Where does clang look for headers?

Clang searches for them in a directory relative to the location of the clang binary. If you moved the clang binary, you need to move the builtin headers, too.

Where does GCC look for header files?

GCC looks for headers requested with #include " file " first in the directory containing the current file, then in the directories as specified by -iquote options, then in the same places it would have looked for a header requested with angle brackets.

Does clang optimize better than GCC?

Clang is much faster and uses far less memory than GCC. Clang aims to provide extremely clear and concise diagnostics (error and warning messages), and includes support for expressive diagnostics. GCC's warnings are sometimes acceptable, but are often confusing and it does not support expressive diagnostics.

Are GCC and Clang interchangeable?

TL;DR: Clang is highly compatible to GCC - just give it a go. In most cases, Clang could be used as a GCC drop in replacement ( clang and clang++ are "GCC compatible drivers").


1 Answers

Either uninstall gcc 4.2 or use the --gcc-toolchain=<value> option.

--gcc-toolchain=<value> Use the gcc toolchain at the given directory

For example: clang++ --gcc-toolchain=/usr/local/... -stdlib=libstdc++ ...

As far as I understand, only libc++ (not libstdc++) is supported by clang for C++11 so the only way it so install libc++?

Both C++ standard libraries are supported.

like image 84
Thomas Avatar answered Oct 15 '22 20:10

Thomas