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. Undefined reference to symbol in static lib
Qt 6.11 is out! See what's new in the release blog

Undefined reference to symbol in static lib

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 2.5k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    Besajia
    wrote on last edited by
    #1

    There are

    lib1.a
    

    lib1 has class Lib1Class

    lib2.a
    

    lib2.a depends on lib1.a and use Lib1Class

    app
    

    app depends of lib2.a and app does not user lib1Class

    app.pro

    TARGET = app
    
    LIBS += -Llibs_path -llib1 -llib2
    
    INCLUDEPATH +=  headers_path
    

    So when I build app I get undefined reference Lib1Class when linking stage.

    Miracle occurs if I start using Lib1Class in app. i.e. in main.cpp create instance of class Lib1Class. Everything is linked and works.

    I tried to use PRE_TARGETDEPS = $${libs_build_dir}/lib1.a and it does not help.

    Help me to build app please.

    https://ubego.ru

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You need to reverse your link order when I'm correct

      LIBS += -Llibs_path -llib2 -llib1

      See also google for 'c++ link order static', e.g. https://eli.thegreenplace.net/2013/07/09/library-order-in-static-linking

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • David_001D Offline
        David_001D Offline
        David_001
        wrote on last edited by David_001
        #3

        lib2.so depends on lib1.so

        => therefore you have to say that inside your pro

        lib2.depends = lib1

        maybe as well
        app.depends = lib1

        1 Reply Last reply
        1

        • Login

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