PDA

View Full Version : Qmake fails to set shared library dependency



jkv
3rd September 2009, 01:41
Hi,

Not sure if this really Qt specific problem, but here goes... :)

I have a Qt gui-project which directory structure after successful build should look like follows (only relevant stuff to my problem, below)


LibBap/ // Links with muparser
LibBap.pro
<sources>
Bap/ // Links with LibBap
Bap.pro
<sources>
BapPlugin/ // Links with LibBap
BapPlugin.pro
<sources>
Extra/
muparser/
muparser.pro
<sources>
bin/
Bap
lib/
libLibBap.so
libmuparser.so
libBapPlugin.so

Build steps before error:

1) libmuparser.so
- built only if system doesn't have this already installed
- compiles/links fine
- moved to bin/lib

2) libLibBap.so
- links with libmuparser.so (either the one in bin/lib or system /usr/lib)
- compiles/links fine
- moved to to bin/lib/

3) Bap
- main executable
- links directly with libLibBap.so (and indirectly on libmuparser.so)
- compiles ok, but linker gives error:

g++ -o ../bin/Bap <objects> -L/usr/lib64/qt4 -L../bin/lib -lBapLib <bunch of -llibs> /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/../../../../x86_64-pc-linux-gnu/bin/ld: warning: libmuparser.so.1, needed by ../bin/lib/libBapLib.so, not found (try using -rpath or -rpath-link)
../bin/lib/libBapLib.so: undefined reference to `mupGetErrorMsg(void*)'
../bin/lib/libBapLib.so: undefined reference to `mupCreate()'
../bin/lib/libBapLib.so: undefined reference to `mupRelease(void*)'
../bin/lib/libBapLib.so: undefined reference to `mupError(void*)'
../bin/lib/libBapLib.so: undefined reference to `mupEval(void*)'
../bin/lib/libBapLib.so: undefined reference to `mupSetExpr(void*, char const*)'
../bin/lib/libBapLib.so: undefined reference to `mupDefineVar(void*, char const*, double*)'
../bin/lib/libBapLib.so: undefined reference to `mupSetVarFactory(void*, double* (*)(char const*, void*), void*)'

So from above it seems to me that linker ignores search path (-L../bin/lib) as it resolves dependencies (libmuparser.so) of libraries linked with -l flag (libBapLib.so).

If I do 'LD_LIBRARY_PATH=../bin/lib make' in Bap/ OR install muparser in /bin/lib instead there is no error. But neither of these is suitable solution in long term.

I tried -rpath and -rpath-link in qmake LIBS variable as the linker suggests but no success. I also tried create_prl and link_prl for BapLib.pro and Bap.pro but no effect. But maybe there is some linker flag or qmake variable that sorts these kind of problems ? I hope there is some obvious thing I missed...

What can I do to let linker know of the second library ?

Thanks!

kwisp
3rd September 2009, 05:21
strange ...

libmuparser.so.1

wysota
3rd September 2009, 08:16
Do you have "libmuparser.so.1" in bin/lib?

faldzip
3rd September 2009, 08:17
add path to the library to /etc/ld.so.conf and run ldconfig (as root)

jkv
3rd September 2009, 12:28
Do you have "libmuparser.so.1" in bin/lib?

Yep. qmake/make creates 4 files in bin/lib: libmuparser.so.1.0.0 which is regular file and libmuparser.so, libmuparser.so.1 and libmuparser.so.1.0 which are all links to the first one.

However I managed to fix this problem by appending -lmuparser to LIBS in Bap.pro. Maybe it was not clear in OP but I didn't have that in the original linker build commandline; I would have thought linker was clever enough to pick up indirect libarary dependencies from -L../bin/lib.

Now I have -lmuparser flag in both BapLib and Bap projects link commands and it seems to work but is it possible there are now duplicated muparser symbols or something in 'Bap' that are not really used at all and take space because it's actually only BapLib code that calls muparser functions ? Or does linker need libmuparser.so just to check that the function definitions do exist (somewhere) ?

wysota
3rd September 2009, 13:44
Nothing is duplicated, this is dynamic linkage - it only says "hey, I depend on X and Y" and X says "hey, I depend on Y" so at runtime the linker thinks "hey, the app depends on X and Y and X depends on Y, so I need to link Y and X before running the app".