Nominate our 2022 Qt Champions!

qt does not try to find a 3rd party lib even though its location is specified

  • I put four 3rd party .so files in total in same folder. And qt can find 3 of them, except only one:

    Below is part of my pro file: (notice that I just put three .so files to LIBS but interestingly, qt find another one automatically.) How can I make qt find the ?

    LIBS += -L$$PWD/lib -lhcnetsdk

    INCLUDEPATH += $$PWD/include/

    (It doesn't matter whether I use . or $$PWD, same result.)

    I mean, actually instead of "cannot find it", qt even didn't TRY to find it. According to strace tool, qt never tried to open() this .so file.

  • FIrst thing you need to use $$PWD.
    Second if you use multiple lines to specify libraries with LIBS, you have to put new line escape charactor so that qmake disregards your line breaks.

    LIBS += -L$$PWD/lib -lhcnetsdk

    INCLUDEPATH += $$PWD/include/


  • @asanka424 Thank you very much, but sorry I just laughed out... I guess you mean $$$PWD rather than $PWD, I did use $$$PWD, just because the display of this post, it displayed my $$$ to $$. and I did add \\ at each end of lines.

  • Lifetime Qt Champion

    What do you actually mean if you say "qt does not try to find a 3rd party lib"?
    Is it not passed to the linker? Can you check in the compiler output whether it is?
    Does this library have the same architecture (32bit vs. 64bit)?

  • @ohuohuo Yes. I didn't know that happened. Are you one Mac, I think in mac you have to include your framework. I will check and let you know. (don't have a Mac right now)

  • Don't you need something like
    LIBS += -Lpathtomylib
    to pass library paths to the linker?

  • @ohuohuo

    Take a look at the Makefile that qmake creates. Is the missing shared lib in it? If not, then there is something wrong with your .pro file.

    Also check the date modified of the Makefile in case for some reason it's not getting updated.

  • @jsulm So "qt does not try to find a 3rd party lib"? means , when I use strace tool in ubuntu12.04, I checked all the open() calls the system made, I didn't find any open() call to file. If it was not passed to the linker, how the other libs were been found? they are in the same folder path, and in the same pro file. I just don't understand

  • @asanka424 No, i'm using ubuntu12.04, 32bit

  • Can you post compile error you get?

  • @asanka424 well, there's no compile error... I guess it's a runtime problem

  • @KeithS Thanks. I checked out the makefile, it seems nothing wrong. Any ideas?
    CC = gcc
    CXX = g++
    CFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
    CXXFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
    INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I../RemoteClient -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I../RemoteClient/include -I../RemoteClient/Configuration/Public -I../RemoteClient/lib -I../RemoteClient -I/usr/X11R6/include -I. -I. -I../RemoteClient -I.
    LINK = g++
    LFLAGS =
    LIBS = $(SUBLIBS) -L/usr/lib/i386-linux-gnu -L/usr/X11R6/lib -L./lib/ -Wl,-rpath=./lib/,-rpath=./ -lhcnetsdk -lPlayCtrl -lMPCtrl -lQtOpenGL -lQtGui -lQtCore -lGL -lpthread
    AR = ar cqs
    RANLIB =
    QMAKE = /usr/bin/qmake-qt4
    TAR = tar -cf
    COMPRESS = gzip -9f
    COPY = cp -f
    SED = sed
    COPY_DIR = $(COPY) -r
    STRIP = strip
    INSTALL_FILE = install -m 644 -p
    INSTALL_PROGRAM = install -m 755 -p
    DEL_FILE = rm -f
    SYMLINK = ln -f -s
    DEL_DIR = rmdir
    MOVE = mv -f
    CHK_DIR_EXISTS= test -d
    MKDIR = mkdir -p

  • @kenchan I changed it to
    LIBS += -L./lib/ -Wl,-rpath=./lib/,-rpath=./ -lhcnetsdk -lPlayCtrl -lMPCtrl
    still cannot find it. any ideas?

  • not really... on MAC OS X I generally put my -LIBS += -Lsomepath and my LIBS += -lsomelib on separate lines. That is just to make it easier to change though.
    I do find that the link order is important for some libraries on UNIX boxes (like Mac OS X).
    Are you using a Mac or something else?
    I might be useful to see what you get in the compile output window.

  • @kenchan no, it's on Ubuntu12.04 32bit. The compile output is:

    23:39:32: Running build steps for project RemoteClient...
    23:39:32: Configuration unchanged, skipping qmake step.
    23:39:32: Starting: "/usr/bin/make" -w
    make: Entering directory /home/.../QtWorkspace/RemoteClient-build-desktop-Qt_4_8_1_in_PATH__System__Debug' make: Nothing to be done forfirst'.
    make: Leaving directory `/home/.../QtWorkspace/RemoteClient-build-desktop-Qt_4_8_1_in_PATH__System__Debug'
    23:39:32: The process "/usr/bin/make" exited normally.

  • hmm not very useful since you are not rebuilding...
    now what does it look like when you do this...
    run qmake
    build or rebuild just to be sure :-)

  • @kenchan yeah, I rebuilt that , but it's large file which part you think would be most interesting?
    output of just ran qmake:
    00:01:05: Running build steps for project RemoteClient...
    00:01:05: Starting: "/usr/bin/qmake-qt4" /home/.../QtWorkspace/RemoteClient/ -r -spec linux-g++ CONFIG+=debug CONFIG+=declarative_debug
    00:01:05: The process "/usr/bin/qmake-qt4" exited normally.

  • @kenchan I looked at the output of ldd, it seems that this program does not depend on and files. And after I changed to unix{
    LIBS += -L./lib/ -Wl,-rpath=./lib/,-rpath=./ -lhcnetsdk -lPlayCtrl -lMPCtrl
    }, I can neither find nor

  • @ohuohuo good point, i guess you mean it is a large project with many source files?
    OK how about cutting a bit that shows the last couple of compiled modules and then the linker stuff up to the end, or is that still too much?

  • so if you don't link to them it will not run, is that the problem?

  • @ohuohuo

    "it seems that this program does not depend on and files"

    So maybe I'm missing something, but from what you have said it seems your app does not depend on the shared libraries hence that's why it doesn't try and load them? What exactly is the error message you are getting when you try and run the app?

    btw I think your LIBS line in the .pro file is not quite right:

    LIBS += -L./lib/ -Wl,-rpath=./lib/,-rpath=./ -lhcnetsdk -lPlayCtrl -lMPCtrl

    The rpath stuff does not belong here, it should be in QMAKE_LFLAGS e.g I have:

    QMAKE_LFLAGS += -rdynamic
    QMAKE_LFLAGS += '-Wl,-rpath,'$$ORIGIN/../lib',-z,origin'

    which makes the executable look in <executable_dir>../lib for the shared libs to be loaded at runtime. Then for 3rd party libs I use:

    LIBS += -L<path_to_lib> -l<lib_name>

    You don't need a trailing '/' after the -L path.

  • If you don't get any compile errors or runtime errors and your only concern is those .so files are not being read while your program is in run, my guess is that your program is not using those library functions at all

  • @asanka424 exactly, so the question is how can I load these libs, I must use functions in them

  • In your code do you call functions from that library?

  • @asanka424 yeah, and when I call it, the SDK will show me an error "Fail to load Player SDK"

  • so when you start your executable it runs but when it reaches that particular call it will show an error? If that is the case, my guess is that your library needs some pluggins and it doesn't find those (or that) pluggin(s).

    I didn't look at the library. Is it related to playing video? If so it probably relying on some codecs. (Just a guess)

  • @asanka424 you know what, I have an example program, which provided by vender, it works fine! no any plugins, no other things, same libs. And I checked out its pro. file, they have same functionalities. while mine just doesn't work...

  • @ohuohuo Ok so this for me to understand your setup.

    You have a code from a vendor you can build and run without any problem

    When you code the same functionality in your code it compiles and runs but gives you errors while its running?

    Am I correct?

  • @kenchan no, it will run nevertheless, but just gives me this error from SDK itself (not leads to a crash) "Failed to load Player SDK" when I call one of its functions in the missing lib. I guess calling other functions in the same lib will be the same result. functions in other libs, which are loaded like is good to call.

  • @asanka424 exactly! well, I mean of course source code is not the same, but same functionalities and the input parameters to the function are correct.

  • @KeithS Thanks much for your reply. But after I used QMAKE_LFLAGS instand of LIBS, a lot of undefined reference errors come out.

  • @ohuohuo in vendors .pro file does it set any rpaths? If your program directly uses any functions of those libraries, it won't compile. Is this a multimedia application?

  • @ohuohuo
    What errors do you get? It may be you have an error in your .pro file.

  • @asanka424 yes. But why it won't compile? I have those dynamic libs, too. It is remote video application, it can connect to a remote device,which as server.

    this is the whole .pro file:

    TEMPLATE = app

    UI_DIR = obj/Gui
    MOC_DIR = obj/Moc
    OBJECTS_DIR = obj/Obj

    TARGET = ../lib/QtClientDemo
    QT += core

    TRANSLATIONS = ../../translation/QtDemo_zh_CN.ts

    RESOURCES = ../../src/Player.qrc

    win32 {

    unix {
    LIBS += -L../lib/ -Wl,-rpath=../lib/,-rpath=./ -lhcnetsdk -lPlayCtrl -lMPCtrl

    HEADERS += ../../src/MainWindow/DeviceTree/DeviceAttr/deviceattr.h
    ... // I replaced a bunch of paths here with ellipsis

    SOURCES += ../../src/MainWindow/DeviceTree/DeviceAttr/deviceattr.cpp
    ... //I replaced a bunch of paths here with ellipsis

    FORMS += ../../src/MainWindow/DeviceTree/DeviceAttr/deviceattr.ui
    ...//I replaced a bunch of paths here with ellipsis

    INCLUDEPATH += ../../src/MainWindow/DeviceTree/
    ...//I replaced a bunch of paths here with ellipsis

    ...//I replaced a bunch of paths here with ellipsis

Log in to reply