How to permanently adding directories to the GCC include search path?
I'm开发者_Python百科 running OSX 10.6.6. I have installed Apples GCC- version 4.2.1. I'm writing myself a nice little library- things for debugging, data storage algorithms, and the like. I've stored all the headers and .c files in a nice little folder called 'mylib' in my C folder. I'd like to add that folder to the GCC search path, so that I can type, say,
/* ... */
#include <mylib/debug.h>
/* ... */
and have it work perfectly. How can I either add /Users/Henry/coding_stuff/c/include/mylib to the GCC search path, or have a reference to the folder in /usr/include? I'd like to not have to replace /usr/include/mylib with the one in my C folder every time I make a trivial change. So, how can it be done?
A symbolic link will work:
sudo ln -s /Users/Henry/coding_stuff/c/include/mylib /usr/include/mylib
A more traditional way to solve this problem is to use the compiler's -I
flag to add your search path:
gcc -I /Users/Henry/coding_stuff/c/include/mylib -c -o example.o example.c
Add to your .bashrc
:
export INCLUDE_PATH=/Users/Henry/coding_stuff/c/include/mylib
You need to set the environment variable LD_LIBRARY_PATH to equal the path. Most likely in your .bashrc.
export LD_LIBRARY_PATH=/path/to/libs
Sorry this should actually be LIBRARY_PATH for the build; LD_LIBRARY_PATH is for runtime library linking.
export LIBRARY_PATH=/path/to/libs
I'm using Ubuntu14.04 and gcc.
gcc adds C_INCLUDE_PATH
to the list of search directories.
You can use -v
option to see where gcc actually searchs.
(INCLUDE_PATH
does not work for me.)
So, you can add the following to .bashrc
:
export C_INCLUDE_PATH=/Users/Henry/coding_stuff/c/include/mylib
I found the official documentation: https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html
精彩评论