I'm trying to programmatically find the #include
path on Linux, which as I understand it, in practice means finding what GCC considers it to be. (Is that quite true? How does Clang do it?)
According to http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html some of the components involve the CPU architecture and the GCC version; the latter in particular seems tricky; I suppose it could be obtained by running gcc --version
and parsing the output (or gcc -v
), but this seems inelegant at best and fragile at worst. Doing it from within one's code assuming one's program is being compiled with GCC might be another option, but it would require depending on that assumption.
What's the recommended way to do it?
You need to use the which command to locate c compiler binary called gcc. Usually, it is installed in /usr/bin directory.
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.
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 ¶
Expand C/C++ General and select Paths and Symbols. Click here to see an illustration (displayed in a separate window). Click Add to define new element (Include Path, Symbol, Library path etc). Click Edit to change selected element (Include Path, Symbol, Library path etc).
The command
echo | gcc -E -Wp,-v -
will show the include path in use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With