m0rtimer m0rtimer - 4 months ago 8
Bash Question

How do I add my own header file directory to Mac Terminal gcc?

I'm trying to compile a C program (myProgram.c) that includes a custom .h file that is in a specified directory. How can I add the directory to gcc so that I can build myProgram.c anytime using just a command like

gcc myProgram
(with no flags and what not)

Answer

You can do this by altering the C_INCLUDE_PATH environment variable, e.g.

C_INCLUDE_PATH=~/include
export C_INCLUDE_PATH

You can add that to your .bashrc or .bash_profile or whatever to always have the environment variable set properly. Here's a reference on how you can do the same for libraries and C++.