ld linkage problems: /usr/bin/ld: cannot find [lib

2019-05-02 09:48发布

问题:

Im using Qmake to build a shared library on Ubuntu 9.10

This shared library (A) has a dependency on another shared library (B).

project B has been successfully built.

in the .pro file for project A, my LIBS variable looks like this:

LIBS += -L../datelib/bin -llibdatelib_release.so.1.0.0

(I used the full shlib name because the library versions are different.)

In any case, when I attempt to build project A, it breaks at the linkage stage, and prints the error message:

/usr/bin/ld: cannot find -llibdatelib_release.so.1.0.0
collect2: ld returned 1 exit status
make[1]: ***[bin/libprojecta_release.so.6.0.0] Error 1
make ***[release] Error 2
Exited with code 2

From the error message, I thought ld was complaining that it could not locate the libdatelib file, so I manually copied it to /usr/lib/

however, that did not solve the problem, and I am getting the same error message.

Anyone knows how to fix this?

[Edit]

I'm quite new to building using gcc. I know how to create symbolic links, but which paths do I use for the lnk command?. The file I want to link to is in /home/username/work/cppdev/datelib/bin.

Also the build system I use (qmake), automatically creates symbolic links as part of the build, so I already have the following files in my /home/username/work/cppdev/datelib/bin folder:

  • libdatelib_release.so (sym link)
  • libdatelib_release.so.1 (sym link)
  • libdatelib_release.so.1.0 (sym link)
  • libdatelib_release.so.1.0.0 (shared lib)

I may have to ask another question to explain why there are so many symlinks (whats the point?), and why I cant just link directly to a shared lib, but have to go through a symbolic link. I've read some online docs, but what I've seen so far seems more like dictum/tradition rather than actual technical reasons WHY this level of abstraction is required when linking on Linux.

回答1:

You can't use -l that way. -l can only find things with names like libFOO.so, via -lFOO. You need a symbolic link without the version number if you want to specify it like this in the build.

Something like:

ln -s /the/path/to/the/libthing.so.1.0.0 /the/path/to/the/libthing.so

Now -lthing will work.



回答2:

The prefix 'lib' is automatically added to the library name - use:

LIBS += -L../datelib/bin -ldatelib_release.so.1.0.0


回答3:

You may provide full path. i.e.

LIBS += ../datelib/bin/libdatelib_release.so.1.0.0

However I would recommend you to do what bmargulies suggested: create symolic link and add -ldatelib_release