linux "-lzlib" - ld cannot find an existing library

x86_64 c++ (7)

As mentioned above the linker is looking for, but you only have

To solve this problem just perform an update cache.

ldconfig -v 

To verify you can run:

$ ldconfig -p | grep libmagic

I am attempting to link an application with g++ on this Debian lenny system. ld is complaining it cannot find specified libraries. The specific example here is ImageMagick, but I am having similar problems with a few other libraries too.

I am calling the linker with:

g++ -w (..lots of .o files/include directories/etc..) \
-L/usr/lib -lmagic

ld complains:

/usr/bin/ld: cannot find -lmagic

However, libmagic exists:

$ locate
$ ls -all /usr/lib/*
lrwxrwxrwx 1 root root    17 2008-12-01 03:52 /usr/lib/ ->
-rwxrwxrwx 1 root root 84664 2008-09-09 00:05 /usr/lib/
$ ldd /usr/lib/ =>  (0xb7f85000) => /usr/lib/ (0xb7f51000) => /lib/i686/cmov/ (0xb7df6000)
    /lib/ (0xb7f86000)
$ sudo ldconfig -v | grep "libmagic" ->

How do I diagnose this problem further, and what could be wrong? Am I doing something completely stupid?

It is Debian convention to separate shared libraries into their runtime components (libmagic1: /usr/lib/ → and their development components (libmagic-dev: /usr/lib/ → …).

Because the library's soname is, that's the string that gets embedded into the executable so that's the file that is loaded when the executable is run.

However, because the library is specified as -lmagic to the linker, it looks for, which is why it is needed for development.

See Diego E. Pettenò: Linkers and names for details on how this all works on Linux.

In short, you should apt-get install libmagic-dev. This will not only give you but also other files necessary for compiling like /usr/include/magic.h.

As just formulated by grepsedawk, the answer lies in the -l option of g++, calling ld. If you look at the man page of this command, you can either do:

  • g++ [...]
  • or: g++ -lmagic [...] , if you have a symlink named in your libs path

In Ubuntu, you can install libtool which resolves the libraries automatically.

$ sudo apt-get install libtool

This resolved a problem with ltdl for me, which had been installed as and wasn't found as simply -lltdl in the make.

Installing libgl1-mesa-dev from the Ubuntu repo resolved this problem for me.

The problem is the linker is looking for but you only have

A quick hack is to symlink to

You can use:

# find . -type f  -name 'text_for_search'

If you want use REGX use -iname

# find . -type f  -iname 'text_for_search'

linux gcc linker shared-libraries shared-objects