Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. linking to a shared object in Linux
Forum Update on Monday, May 27th 2025

linking to a shared object in Linux

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mzimmers
    wrote on 28 May 2017, 01:22 last edited by mzimmers
    #1

    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 -l097sharedlib.so
    

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

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

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

    Thanks...

    K 1 Reply Last reply 28 May 2017, 01:50
    0
    • M mzimmers
      28 May 2017, 01:22

      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 -l097sharedlib.so
      

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

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

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

      Thanks...

      K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 28 May 2017, 01:50 last edited by
      #2

      Ordinarily libraries are prefixed on Linux, so a library named SomeLibrary will be present on the filesystem as libSomeLibrary.so. 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
      

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      5
      • M Offline
        M Offline
        mzimmers
        wrote on 28 May 2017, 02:10 last edited by
        #3

        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.
        DEFINES += QT_DEPRECATED_WARNINGS
        
        # 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 \
            _097sharedlib_global.h
        
        
        
        1 Reply Last reply
        0
        • M Offline
          M Offline
          mzimmers
          wrote on 28 May 2017, 02:20 last edited by
          #4

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

          1 Reply Last reply
          2

          1/4

          28 May 2017, 01:22

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved