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?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Henry
  • 121
  • 1
  • 2
  • 5

4 Answers4

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
Carl Norum
  • 219,201
  • 40
  • 422
  • 469
1

Add to your .bashrc:

export INCLUDE_PATH=/Users/Henry/coding_stuff/c/include/mylib
Sophie Alpert
  • 139,698
  • 36
  • 220
  • 238
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

ywat
  • 2,757
  • 5
  • 24
  • 32
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
Suroot
  • 4,315
  • 1
  • 22
  • 28