Linking with a different .so file in linux


I'm trying to compile a piece of software which has the standard build process e.g.

configure make make install

The software requires a library e.g. libreq.so which is installed in /usr/local/lib. However, my problem is I'd like to build the software and link it with a different version of the same library (i have the source for the library as well) that I've installed in /home/user/mylibs.

My question is, how do I compile and link the software against the library in /home/user/mylibs rather than the one in /usr/local/lib

I tried setting "LD_LIBRARY_PATH" to include /home/user/mylibs but that didn't work.



When you have an autoconf configure script, use:

CPPFLAGS=-I/home/user/include LDFLAGS=-L/home/user/mylibs ./configure ...

This adds the nominated directory to the list of directories searched for headers (usually necessary when you're using a library), and adds the other nominated directory to the list searched for actual libraries.

I use this all the time - on my work machine, /usr/local is 'maintained' by MIS and contains obsolete code 99.9% of the time (and is NFS-mounted, read-only), so I struggle to avoid using it at all and maintain my own, more nearly current, versions of the software under /usr/gnu. It works for me.


Try using <a href="http://en.wikipedia.org/wiki/Dynamic_linker#LD_PRELOAD" rel="nofollow">LD_PRELOAD</a> set to your actual file.


LD_LIBRARY_PATH is for finding the dynamic link libraries at runtime. At compiling you should add -L parameters to gcc/g++ to specify in which directory the *.so files are. You also need to add the library name with -l<NAME> (where the library is libNAME.so).

Important! For linking you not only need the libNAME.so file but a libNAME.a is needed too.

When you run the application, don't forget to add the dir to the LD_LIBRARY_PATH.


When you added the /home/user/mylibs to the LD_LIBRARY_PATH did you add it to the front or end of the existing paths? The tokens are searched in-order so you will want yours to appear first in the list.

Also, many standard build environments that use configure will allow you to specify an exact library for each required piece. You will have to run ./configure --help but you should see something like --using-BLAH-lib=/path/to/your/library or similar.


  • Portable access to sysconfdir via config.h
  • Celery + Django on Elastic Beanstalk causing error: ,
  • Access Google spreadsheet API without Oauth token
  • LD_LIBRARY_PATH without export
  • Setting path to shared library inside a makefile for compile
  • Autoconf triplet for Android x86_64?
  • MacOS - automake: command not found
  • How can I run cl using x64?
  • mysql connection with visual studio c++
  • What is the difference between DEFS and CPPFLAGS in autoconf and automake
  • using magma_dysevd in mex file matlab
  • PySide's shiboken python module not found
  • What are LINK.cpp / COMPILE.cpp Variables good for in make?
  • How to change current directory in Make
  • --enable-static vs --disable-shared
  • libmemcached path?
  • How to make the target depend on lib file, but exclude it from $^ (VPATH involved)?
  • GTK+ compilation undefined reference C
  • build.xml expects tools.jar at a different location
  • Tutorial for installing numpy with OpenBLAS on Windows
  • RubyMine 3.2 failing to find libmysqlclient.18.dylib on MacOS Lion
  • Typescript 2.1.5 Function calls are not supported
  • ImageMagick not converting
  • Compile ffmpeg as stand alone binary
  • Is it safe to accept URL parameters for populating the `url_for` method?
  • How do I retrieve the user information of a user authenticated with Apache's mod_ldap?
  • Ember.js model to be organised as a tree structure
  • How do I configure context broker accept post requests from my remote sensor?
  • How does document.ready work with angular element directives?
  • WPF - CanExecute dosn't fire when raising Commands from a UserControl
  • Paperclip, set path outside of rails root folder
  • DomPDF {PAGE_NUM} not on first page
  • Javascript simulate pressing enter in input box
  • swift auto completion not working in Xcode6-Beta
  • 'TypeError' while using NSGA2 to solve Multi-objective prob. from pyopt-sparse in OpenMDAO
  • Importing jscolor library in angular 2
  • A cron job substitute?
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • Linking SubReports Without LinkChild/LinkMaster
  • How to get NHibernate ISession to cache entity not retrieved by primary key