Important: Please read the Qt Code of Conduct -

linking to a shared object in Linux

  • Hi -

    I'm trying to follow a very simple tutorial on using shared libraries. Unfortunately for me, the author of the tutorial used Windows as his platform, and I'm trying to do this on Linux.

    I've created the library, and have moved them into the source directory of my app that is to use the library. When I build, I get this error message:

    :-1: error: cannot find

    I've put this line in my .pro file:

    LIBS += -L/home/mzimmers/QtStuff/tutorials/098sharedlibuser

    According the wiki, this should work. What might I be doing wrong?


  • Qt Champions 2017

    Ordinarily libraries are prefixed on Linux, so a library named SomeLibrary will be present on the filesystem as Whenever you link it through the LIBS variable you don't specify the prefix nor the suffix, so you'd link as:

    LIBS += -L/path/to/some/library -lSomeLibrary

  • Hi, Kshegunov -

    Thanks for that; I'd forgotten about that little Linux nauance. Unfortunately, it's still giving me the same error code. Here's the .pro file:

    QT += core
    QT -= gui
    CONFIG += c++11
    TARGET = 098sharedlibuser
    CONFIG += console
    CONFIG -= app_bundle
    LIBS += -L/home/mzimmers/QtStuff/tutorials/098sharedlibuser -l097sharedlib
    TEMPLATE = app
    SOURCES += main.cpp
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which as been marked deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    HEADERS += \
        _097sharedlib.h \

  • Oops - disregard my latest message. I'd neglected the "_" at the start of the library name. Now I build OK. Thanks!

Log in to reply