M
M
mik_os2012-08-29 17:28:12
Qt
mik_os, 2012-08-29 17:28:12

G++ and linking order

I have a working Qt application. I'm trying to build it into a static exe. Stuck on the following problem:

The phonon_ds9 plugin does not want to link. Throws out a sheet undefined reference: pastebin.com/fQmF5Q6a
Namely, a plug on the following command:

g++ -Wl,-s -mthreads -Wl,-subsystem,windows -o release\app.exe object_script.app.Release  -L"d:\qt\qt-libs\lib" -lmingw32 -lqtmain -ldnsapi -ldxguid -lstrmiids -lmsdmo -ldmoguids -LD:/qt/qt-libs/plugins/phonon_backend -lphonon_ds9 -lphonon -lQtXml -lQtOpenGL -lQtNetwork -lglu32 -lopengl32 -lQtGui -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lmsimg32 -lQtCore -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32 -LD:\src\openssl-1.0.1c

But if you change the order of the libraries to this (dxguid, strmiids, msdmo, dmoguids that phonon_ds9 requires, move to the end):
g++ -Wl,-s -mthreads -Wl,-subsystem,windows -o release\app.exe object_script.app.Release  -L"d:\qt\qt-libs\lib" -lmingw32 -lqtmain -ldnsapi -LD:/qt/qt-libs/plugins/phonon_backend -lphonon_ds9 -lphonon -lQtXml -lQtOpenGL -lQtNetwork -lglu32 -lopengl32 -lQtGui -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lmsimg32 -lQtCore -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32 -LD:\src\openssl-1.0.1c -ldxguid -lstrmiids -lmsdmo -ldmoguids

That linking is completed successfully. Why?
ps The top command is generated by qmake.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
mejedi, 2012-08-29
@mejedi

second answer

M
Mezomish, 2012-08-29
@Mezomish

Just recently there was an excellent article about the linker, read it .
In particular,

Another important detail is the order of events; libraries are only brought in when normal linking is complete, and they are processed in left-to-right order. This means that if the object retrieved last from the library requires a symbol from the library that is earlier in the link line, then the linker will not automatically find it.

By the way, does qmake generate this by default, or did you yourself add these libraries to .pro, to the LIBS section? If the latter, then change the order there.

M
mik_os, 2012-08-29
@mik_os

Yes, I read the article, but for some reason I thought that since one binary is being linked with one command, the linker must figure it out himself ... Yes, the situation is exactly like in this quote.
I added libraries. They are already at the end, but qmake adds "-LD:/qt/qt-libs/plugins/phonon_backend -lphonon_ds9" (QTPLUGIN += phonon_ds9) _after_ them.
Apparently the solution would be to remove phonon_ds9 from QTPLUGIN and calculate the path to qt-dir/plugins/phonon_backend yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question