PDA

View Full Version : Linker can't resolve Qt symbols when building outside of creator



CentralScrutinizer
2nd March 2018, 16:41
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) however 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?

d_stranz
3rd March 2018, 23:55
Shouldn't all of these kind of things: "C:\Qt5.7\5.7\mingw53_32\lib\libQt5Widgets.a" be listed as "-lQt5Widgets" instead? You're already using the -L option to tell it where the libraries are. I don't think that simply listing the paths to the libraries works - you need to tell the linker that they are libraries by using the -l option on each one, AFAIK.

Also, unlike the Microsoft Visual Studio linker, it is my experience that libraries must be listed in the order of dependency - if one library (A) depends on symbols from another (B), A must be listed before B on the link line.


"Some people like cupcakes better. I for one care less for them!"