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" if MinGW/Linux, MSVS works. Subdirs project.
Forum Updated to NodeBB v4.3 + New Features

"Undefined reference" if MinGW/Linux, MSVS works. Subdirs project.

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 566 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.
  • S Offline
    S Offline
    Szymon. M. Sabat
    wrote on 25 Oct 2020, 22:24 last edited by
    #1

    I have subdirs project with some internal libraries and apps which use them. Everything builds and runs fine with x64 MSVS2019 kit but fails terribly on build when I try to use x64 MinGW; a lot of "undefined reference" errors all of sudden. Same errors appear on x64 Linux.

    Dependencies structure. If an app needs a library or a library needs some other library, I add this to its PRO file (sometning depended on MyCore library as an example):

    win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../MyCore/release/ -lMyCore
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../MyCore/debug/ -lMyCore
    else:unix: LIBS += -L$$OUT_PWD/../MyCore/ -lMyCore
    INCLUDEPATH += $$PWD/../MyCore
    DEPENDPATH += $$PWD/../MyCore
    win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../MyCore/release/libMyCore.a
    else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../MyCore/debug/libMyCore.a
    else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../MyCore/release/MyCore.lib
    else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../MyCore/debug/MyCore.lib
    else:unix: PRE_TARGETDEPS += $$OUT_PWD/../MyCore/libMyCore.a
    

    If a library or app needs a library which depends on some other library, I add both to the PRO file just like in the example and in ordered manner just to be safe. So let's say I have an MyApp app which needs MyEngine and MyEngine needs MyCore; then MyEngine.pro has what I presented in the example and MyApp.pro has it doubled:

    win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../MyCore/release/ -lMyCore
    [...]
    win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../MyCore/release/ -lMyEngine
    [...]
    

    Then in the main PRO file it looks like this:

    TEMPLATE = subdirs
    
    SUBDIRS += \
        MyCore \
        MyEngine \
        MyApp
    
    MyEngine.depends = MyCore
    MyApp.depends = MyCore MyEngine
    

    Sometimes:

    OtherApp.depends = MyCore
    OtherApp.depends +=  MyEngine
    

    I'm using examples because the real dependencies are quite broad but it's works with MSVS so I assume there are no typos or whatnot. What may be wrong and what additional information should I provide? I want my apps to run on Linux, I don't believe I was using any platform-depended code.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 26 Oct 2020, 17:42 last edited by
      #2

      You did not tell which functions are missing nor showing us any code regarding the missing functions.

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

      S 1 Reply Last reply 27 Oct 2020, 01:56
      0
      • C Christian Ehrlicher
        26 Oct 2020, 17:42

        You did not tell which functions are missing nor showing us any code regarding the missing functions.

        S Offline
        S Offline
        Szymon. M. Sabat
        wrote on 27 Oct 2020, 01:56 last edited by
        #3

        @Christian-Ehrlicher because I figured it's all of them. Deleting some just brings other functions to err just like the library file wouldn't be there at all or something. I also assumed that it's not my code at fault but the configuration of the linker as everything was working just fine with the other kit.

        I changed my libs to be dynamic, not static and now it just works everywhere for every kit.

        K 1 Reply Last reply 27 Oct 2020, 06:34
        0
        • S Szymon. M. Sabat
          27 Oct 2020, 01:56

          @Christian-Ehrlicher because I figured it's all of them. Deleting some just brings other functions to err just like the library file wouldn't be there at all or something. I also assumed that it's not my code at fault but the configuration of the linker as everything was working just fine with the other kit.

          I changed my libs to be dynamic, not static and now it just works everywhere for every kit.

          K Offline
          K Offline
          KroMignon
          wrote on 27 Oct 2020, 06:34 last edited by
          #4

          @Szymon-M-Sabat said in "Undefined reference" if MinGW/Linux, MSVS works. Subdirs project.:

          I changed my libs to be dynamic, not static and now it just works everywhere for every kit.

          Maybe a silly question, but did you export classes / functions with Q_DECL_EXPORT to make them accessible? This is required for Windows systems.
          Take a look at https://doc.qt.io/qt-5/sharedlibrary.html for more details.

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          S 1 Reply Last reply 27 Oct 2020, 14:55
          1
          • K KroMignon
            27 Oct 2020, 06:34

            @Szymon-M-Sabat said in "Undefined reference" if MinGW/Linux, MSVS works. Subdirs project.:

            I changed my libs to be dynamic, not static and now it just works everywhere for every kit.

            Maybe a silly question, but did you export classes / functions with Q_DECL_EXPORT to make them accessible? This is required for Windows systems.
            Take a look at https://doc.qt.io/qt-5/sharedlibrary.html for more details.

            S Offline
            S Offline
            Szymon. M. Sabat
            wrote on 27 Oct 2020, 14:55 last edited by
            #5

            @KroMignon isn't export for dynamic libs? I now use the libs as dynamic with export and it works, before that I was using them as static so w/o export. Also, Windows was actually not a problem, Linux was.

            K 1 Reply Last reply 27 Oct 2020, 15:33
            0
            • S Szymon. M. Sabat
              27 Oct 2020, 14:55

              @KroMignon isn't export for dynamic libs? I now use the libs as dynamic with export and it works, before that I was using them as static so w/o export. Also, Windows was actually not a problem, Linux was.

              K Offline
              K Offline
              KroMignon
              wrote on 27 Oct 2020, 15:33 last edited by
              #6

              @Szymon-M-Sabat said in "Undefined reference" if MinGW/Linux, MSVS works. Subdirs project.:

              isn't export for dynamic libs?

              Your right, I read too fast the post, sorry for the noise.

              With static libs diamond references is not possible, as far as I know.
              When using static libs, be sure the static libs are not linked again each other.
              Link must only be done in final library/executable.

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              S 1 Reply Last reply 27 Oct 2020, 17:22
              1
              • K KroMignon
                27 Oct 2020, 15:33

                @Szymon-M-Sabat said in "Undefined reference" if MinGW/Linux, MSVS works. Subdirs project.:

                isn't export for dynamic libs?

                Your right, I read too fast the post, sorry for the noise.

                With static libs diamond references is not possible, as far as I know.
                When using static libs, be sure the static libs are not linked again each other.
                Link must only be done in final library/executable.

                S Offline
                S Offline
                Szymon. M. Sabat
                wrote on 27 Oct 2020, 17:22 last edited by
                #7

                @KroMignon oh, so that's probably it, I didn't know that.

                1 Reply Last reply
                0

                1/7

                25 Oct 2020, 22:24

                • Login

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