2

I'm 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?

1

4 Answers 4

4

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 
Sign up to request clarification or add additional context in comments.

Comments

1

Add to your .bashrc:

export INCLUDE_PATH=/Users/Henry/coding_stuff/c/include/mylib 

1 Comment

Yeah! Thats it woman thx!
0

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 

2 Comments

LD_LIBRARY_PATH is not for #include path resolution.
LIBRARY_PATH is not for #include paths either.
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.