Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

-I option set header file searching path for gcc/g++, and CPLUS_INCLUDE_PATH/CPATH append the searching path list.

Then what about libs? It seems that LD_LIBRARY_PATH is just a path list for run-time library searching. -L option is necessary to specify any lib path other than /usr/lib and /usr/local/lib.

Is there an environment variable similar to CPATH/CPLUS_INCLUDE_PATH, to do the compile-time job?

share|improve this question
LD_LIBRARY_PATH is used for the run-time search of dynamically linked libraries, as those are dynamically linked libraries. If you want something defined on compile time, have you considered statically-linked libraries? (You get this by passing the -static option to gcc or to the linker.) – njsg Jul 9 '12 at 8:34
There is nothing to worry about runtime execution. I just want to configure the compile environment in my .bashrc rather than gcc command line. – Martin Wang Jul 9 '12 at 8:57
Oh, got it. From the manpage, I guess LIBRARY_PATH is what you're looking for, "The value of LIBRARY_PATH is a colon-separated list of directories, [...] Linking using GCC also uses these directories when searching for ordinary libraries for the -l option (but directories specified with -L come first)." – njsg Jul 9 '12 at 9:23
Also, if you're going through your first steps in program compilation, be sure to read a bit about Makefiles and make, which are one of the ways to automate the compile options and procedures for a project. – njsg Jul 9 '12 at 9:25
LIBRARY_PATH works – Martin Wang Jul 9 '12 at 9:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.