Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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 built a C library (compiled from source) below my home folder and now I have to build a new package that depends on that library. When running the configure script I get the error
configure: error: The required <package> library was not found.

Is there an environment variable I can edit to make my script search the library's path?

I already tried LD_LIBRARY_PATH

share|improve this question
up vote 3 down vote accepted
  • Many libraries use pkg-config, so tell it where to find your locally installed .pc files:

    export PKG_CONFIG_PATH="$LOCAL/lib/pkgconfig:$LOCAL/share/pkgconfig"

    (The system-wide directories will be included automatically.)

    Sometimes a library-specific command is used instead of the generic pkg-config; for example, krb5-config. In this case, point to your bin directory:

    export PATH="$LOCAL/bin:$PATH"
  • If pkg-config is not used, you will have to manually point the compiler and linker to the right place.

    export CFLAGS="-I$LOCAL/include"     # for the C compiler
    export CXXFLAGS="-I$LOCAL/include"   # for the C++ compiler
    export LDFLAGS="-L$LOCAL/lib"        # for the linker
  • ./configure --help will usually list a series of --with-feature=... options, which allow specifying locations of each library separately.

    Often, ./configure --help will also list environment variables for each library (such as CURL_CFLAGS and CURL_LIBS); look for "C compiler flags" or "linker flags" in the help text.

    If you often need more than one custom library, this will quickly become inconvenient; you should instead specify pkg-config path and cflags for all libraries at once.

  • You may also need to point the loader to your library location while compiling. For Linux, it would be:

    export LD_LIBRARY_PATH="$LOCAL/lib"

    This shouldn't be necessary when running compiled programs; the linker will have added the correct paths to the compiled binary itself (look for "Library rpath" in readelf -d yourprogram if you want to check).

    For Mac OS X, setting DYLD_LIBRARY_PATH should have a similar effect; otool can be used for inspecting applications.

In all examples above, $LOCAL will be the prefix you used when installing libraries; for example, if you did ./configure --prefix ~/usr, then use ~/usr here.

share|improve this answer
+1 for all the useful information. I got it to work before seeing your answer but I had to go in and edit the configure script. – Yitzchak Nov 16 '11 at 23:36

If you haven't installed the library, you'll need to pass its include path to your configure script, similar to what is described in this question.

LD_LIBRARY_PATH would be used after you get it compiled, so you can find the library at runtime.

share|improve this answer

You must log in to answer this question.

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