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
Forum Updated to NodeBB v4.3 + New Features

Undefined reference to symbol in static lib

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 1.4k 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 16 Aug 2019, 19:00 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
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 16 Aug 2019, 19:24 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
      • D Offline
        D Offline
        David_001
        wrote on 16 Aug 2019, 19:48 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

        1/3

        16 Aug 2019, 19:00

        • Login

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