Important: Please read the Qt Code of Conduct -

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

  • 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 has what I presented in the example and 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 \
    MyEngine.depends = MyCore
    MyApp.depends = MyCore MyEngine


    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.

  • Lifetime Qt Champion

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

  • @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.

  • @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 for more details.

  • @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.

  • @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.

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

Log in to reply