I’m building a simple C++ program and I want to temporarily substitute a system supplied shared library with a more recent version of it, for development and testing.

I tried setting the LD_LIBRARY_PATH variable but the linker (ld) failed with:

/usr/bin/ld: cannot find -lyaml-cpp

I expected that to work because according to the ld man page:

The linker uses the following search
paths to locate required shared
libraries: … For a native linker,
the contents of the environment variable

I then tried setting the LIBRARY_PATH, and that worked.

According to the GCC manual:

The value of
LIBRARY_PATH is a colon-separated list
of directories, much like PATH. When
configured as a native compiler, GCC
tries the directories thus specified
when searching for special linker
files, if it can’t find them using
GCC_EXEC_PREFIX. Linking using GCC
also uses these directories when
searching for ordinary libraries for
the -l option (but directories
specified with -L come first).

As the (GCC) manual suggests, LIBRARY_PATH works because I link with GCC.


  • Since I link with gcc why ld is
    being called, as the error message
  • What’s the point of
    having two variables serving the same
    purpose? Are there any other

4 Answers

Leave a Comment