Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query the default include paths of clang++?

Tags:

How can I query the default include path of clang/clang++? I am trying to use a custom built clang compiler (the one that supports OpenMP), but it doesn't seem to find the STL libraries:

/usr/local/bin/clang++ hello.cpp  hello.cpp:1:10: fatal error: 'iostream' file not found #include <iostream>      ^ 1 error generated. 

By using an IDE, back-tracking the #include iostream, and finally using the -isystem option I got the simple helloworld application to compile in OSX 10.9:

/usr/local/bin/clang++ -isystem /Library/Developer/CommandLineTools/usr/lib/c++/v1 hello.cpp 

Thanks for your help!

like image 976
andrea Avatar asked May 14 '14 12:05

andrea


People also ask

How do I find my GCC path?

You need to use the which command to locate c compiler binary called gcc. Usually, it is installed in /usr/bin directory.

Where is include path?

System include paths are standard locations to find source code tags, such as the header files in /usr/include and its subdirectories on Unix-like operating systems. You can add and remove system include paths using the following commands: Command: semantic-add-system-include dir &optional mode ¶

What is clang cc1?

The -cc1 argument indicates that the compiler front-end is to be used, and not the driver. The clang -cc1 functionality implements the core compiler functionality. So, simply speaking. If you do not give -cc1 then you can expect the "look&feel" of standard GCC.

Where does clang look for?

Some header files ( stddef. h , stdarg. h , and others) are shipped with Clang — these are called builtin includes. Clang searches for them in a directory relative to the location of the clang binary.


2 Answers

You are looking for option -v. Compiling with clang++ -c file.cc -v will print among other things:

#include "..." search starts here: #include <...> search starts here:  /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9 

etc.

like image 127
Marc Glisse Avatar answered Oct 04 '22 11:10

Marc Glisse


If you run

clang++ -### hello.cpp 

It will display the commands used to compile that particular file, including the default include paths, library search paths, targets etc.

like image 34
Andrew Marshall Avatar answered Oct 04 '22 10:10

Andrew Marshall