Monday, July 15, 2013

C++ and gcc on Linux/Mac: How to set your custom directory to include header files

Your profile:
You are using OSX or Linux and you are writing some code in C/C++  compiling it with gcc...
how can you modify the path in which gcc looks for your header files?

Simply enough you have to modify two environment variables: C_INCLUDE_PATH and CPLUS_INCLUDE_PATH, for C and C++ respectively.


Example:
Suppose you want to add the directory /opt/local/include for a C++ project in this case:

export CPLUS_INCLUDE_PATH=${CPLUS_INCLUDE_PATH}:/opt/local/include

in a similar way you can modify the C_INCLUDE_PATH variable.


NOTE
To make this modification permament for every new terminal session, the export line must be put into the hidden .bash_profile file in your home directory.
 

No comments:

Post a Comment

Your comment will be visible after approval.