Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Link errors when building with qmake outside of Creator



  • Hi All,

    I have a Qt based shared library (of our own creation) that I can't build outside of creator in (Windows/MinGW-32 5.3). It works fine (compiles and links) in QtCreator. However, when I attempt to build from the command line using the same qmake project files (qmake/mingw32-make), when linking the dll, the linker spits out an undefined reference for every single Qt symbol used in my library like so:

    g++ -Wl,-s -shared -Wl,-subsystem,windows -mthreads -Wl,--out-implib,release\libOslQtCommon.a -o release\OslQtCommon.dll object_script.OslQtCommon.Release  -LD:\workspace-qt\Gordon_v1_0_1_b01\OslCommon\release -lOslCommon -LD:\workspace-qt\Gordon_v1_0_1_b01\IcIface\release -lIcIface -lws2_32 -liphlpapi -LC:\Qt5.7\5.7\mingw53_32\lib C:\Qt5.7\5.7\mingw53_32\lib\libQt5Widgets.a C:\Qt5.7\5.7\mingw53_32\lib\libQt5Gui.a C:\Qt5.7\5.7\mingw53_32\lib\libQt5Ftp.a -LC:\utils\postgresql\pgsql\lib -LC:\utils\my_sql\my_sql\lib C:\Qt5.7\5.7\mingw53_32\lib\libQt5Network.a C:\Qt5.7\5.7\mingw53_32\lib\libQt5SerialPort.a C:\Qt5.7\5.7\mingw53_32\lib\libQt5Core.a 
    ./obj\oslwavlogger.o:oslwavlogger.cpp:(.text+0x950): undefined reference to `__imp__ZN7QObjectC2EPS_'
    ./obj\oslwavlogger.o:oslwavlogger.cpp:(.text+0x96a): undefined reference to `__imp__ZN7QString13toUtf8_helperERKS_'
    ./obj\oslwavlogger.o:oslwavlogger.cpp:(.text+0xa21): undefined reference to `__imp__ZN10QArrayData10deallocateEPS_yy'
    ./obj\oslwavlogger.o:oslwavlogger.cpp:(.text+0xa37): undefined reference to `__imp__ZN7QObjectD2Ev'
    ./obj\oslwavlogger.o:oslwavlogger.cpp:(.text+0xb94): undefined reference to `__imp__ZN7QObjectD2Ev'
    ./obj\oslwavlogger.o:oslwavlogger.cpp:(.text+0xbad): undefined reference to `__imp__ZN10QArrayData10deallocateEPS_yy'
    ./obj\oslwavlogger.o:oslwavlogger.cpp:(.text+0xbcd): undefined reference to `__imp__ZN10QArrayData10deallocateEPS_yy'
    ./obj\oslwavlogger.o:oslwavlogger.cpp:(.text+0xc55): undefined reference to `__imp__ZN7QString15fromUtf8_helperEPKci'
    ./obj\oslwavlogger.o:oslwavlogger.cpp:(.text+0xc8d): undefined reference to `__imp__ZN7QString6appendERKS_'
    ./obj\oslwavlogger.o:oslwavlogger.cpp:(.text+0xd2b): undefined reference to `__imp__ZN10QArrayData10deallocateEPS_yy'
    ./obj\oslwavlogger.o:oslwavlogger.cpp:(.text+0xd4d): undefined reference to `__imp__ZN10QArrayData10deallocateEPS_yy'
    ./obj\oslwavlogger.o:oslwavlogger.cpp:(.text+0xd6d): undefined reference to `__imp__ZN10QArrayData10deallocateEPS_yy'
    [... ad infinitum]
    

    I have compared the linker command used by Creator and it is identical to the one running at the command line except the paths since I'm building to a different location (I'm using a python script to generate the qmake/make cmds with the same options I have in creator). Since everything compiles OK and the linker has no problem finding the library files (all of Qt's .a/dll files) I'm thinking somehow the symbols are not being exported or imported. But as I said, here's no problem building in Creator so I guess this probably means Creator has something in its environment that is missing in my python environment but I can't figure it out. What would cause these (and all Qt symbols) to not get exported (or imported)?

    Any ideas?


  • Moderators

    Move QtCore include to the front of library includes. Linker is sequential, so when it tries to link QtWidgets, it does not see the QtCore symbols because they are not loaded yet.

    If it's not that, then take a look at all Qt Creator env. variables, they are shown in Project settings -> build environment.


  • Moderators

    @CentralScrutinizer Are you sure you are using the same qmake that your qt creator is using? It's possible you aren't and it's trying to mix Qt libs which I've seen cause this issue in the past.

    Other than that, share your .pro file. :)



  • Thanks for the helpful answers. It turned out to be my environment. For some reason I had an extra path in my PATH variable that pointed to another make (mingw64-make in my MSYS installation). I have no Idea why that affected my ability to build at the command line (esp. since I use full absolute paths for all of the commands used in the build) but removing it seemed to do the trick. I also don't understand why the mingw paths are needed on the PATH at all when using absolute paths. Or why it worked inside creator. Oh well I don't have time to investigate any further so i'll just have to be satisfied with it working now. Thanks again


Log in to reply