2

-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?

5
  • 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, 2012 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. Jul 9, 2012 at 8:57
  • 2
    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, 2012 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, 2012 at 9:25
  • 1
    LIBRARY_PATH works Jul 9, 2012 at 9:35

1 Answer 1

5

This Q appears to have been answered in the comments. Per njsg's comment,

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)."

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .