Linux library link configuration (

In Linux system, understanding of how system or application library works is very important. Many applications you download are source files which need to be compiled. for example: qmake, make, make install.
After "make" the source file (typically lib), the lib files will be created, such as:

ln -s
ln -s
ln -s

but these lib file are not installed in Linux system.
After "make install", all lib files has been installed in Linux system.

ln -f -s "" "/usr/local/lib/"
ln -f -s "" "/usr/local/lib/"
ln -f -s "" "/usr/local/lib/"

However, even you "make install" lib files, you may still get error message when you run Qt application. for example, I "make install" QuaZIP package, and successfully compile a which come with this package, but i still got error message when i run the program:

Starting /home/czhang/quazip-0.3/test/zip-build-desktop/zip...
/home/czhang/quazip-0.3/test/zip-build-desktop/zip: error while loading shared libraries: cannot open shared object file: No such file or directory
/home/czhang/quazip-0.3/test/zip-build-desktop/zip exited with code 127

Why?!! I have been struggling on this problem for long time.

Here is what i understand and solve the problem.

First of all, take a look at "ldconfig" - configure dynamic linker run-time bindings
$ man ldconfig
All applications, if they need lib to run, will check from here first /etc/
take a look
$ cat /etc/
include /etc/*.conf

It re-direct to /etc/  and all .conf file will be checked through.
Let's take a look at folder
$ ls /etc/

GL.conf            libasound2.conf   x86_64-linux-gnu.conf
lib32asound2.conf  libc.conf        Qtlib.conf

in here, we can see a Qtlib.conf file. If you take a look at it, you will see all Qt lib is setting in

When I "make install" QuaZip package, I got message like:

ln -f -s "" "/usr/local/lib/"
ln -f -s "" "/usr/local/lib/"
ln -f -s "" "/usr/local/lib/"

This means all QuaZip libs are stored in /usr/local/lib/

So, I create a new .conf file which call qauzip.conf
$ gedit qauzip.conf
add "/usr/local/lib" in it.

From now on, when Qt tries to use QuaZip lib, it can be found.

Re-compile my "", and run it, works! :)

Happy end.

or, just simply
$ sudo cp -a /home/czhang/quazip-0.3/quazip libquazip* /usr/lib64

when i compile my own program which including QuaZip, i got error messages:

error: undefined reference to `QuaZip::QuaZip(QString const&)'
error: undefined reference to `QuaZip::open(QuaZip::Mode, zlib_filefunc_def_s*)'

Then I took a look .pro file,

INCLUDEPATH += /home/czhang/quazip-0.3/quazip
LIBS += -L -lquazip

Actually, I don't really understand the -L. After doing some studies, i learned:

This variable specifies the #include (normally header file) directories which should be searched when compiling the project.

This variable contains a list of libraries to be linked into the project. You can use the Unix -l (library) and -L (library path) flags and qmake will do the correct thing with these libraries on Windows (namely this means passing the full path of the library to the linker). The only limitation to this is the library must exist, for qmake to find which directory a -l lib lives in.

Therefore, my .pro file should be like:

INCLUDEPATH += /home/czhang/quazip-0.3/quazip
LIBS += -L/home/czhang/quazip-0.3/quazip -lquazip
INCLUDEPATH += /home/czhang/quazip-0.3/quazip
LIBS += -lquazip

$ rsync -av czhang@
ensource-src-4.7.0/projects/quazip-0.3/quazip/* /usr/lib

1 comment:

  1. Anonymous2/8/12 07:58

    Thanks a lot! This was very useful information. I've been struggling with getting quazip to work in my Qt app as well. Great post.