1

I have a static version of QT compiled like this:

@echo off

SET QTDIR=%~dp0%
SET QMAKESPEC=win32-g++
SET PATH=%PATH%;%QTDIR%/gcc

call configure -release -nomake examples -nomake tools -static -static-runtime -opensource -confirm-license -platform win32-g++ -ltcg -c++std c++11 -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -fontconfig -qt-harfbuzz -qt-sql-sqlite -prefix %QTDIR%/gcc

mingw32-make -j4
mingw32-make install

And I have a sample program that look like this:

#include <QtWidgets/QApplication>
#include <QtWidgets/QMainWindow>
#include <QtCore/QtPlugin>
Q_IMPORT_PLUGIN (QWindowsIntegrationPlugin);

int main(int argc, char** argv){

    QApplication app(argc, argv);
    QMainWindow w;

    w.resize(600,600);
    w.show();
    app.exec();

    return 0;
}

Now when I try to compile it with cmake like this:

ADD_EXECUTABLE( ${PROJECT_NAME} WIN32 "main.cpp")
TARGET_LINK_LIBRARIES(${PROJECT_NAME} Qt5Widgets qwindows Qt5Gui Qt5Core qtmain Qt5Gui Qt5OpenGL Qt5OpenGLExtensions Qt5PlatformSupport qtfreetype dxguid d3d9 d3dx9 imm32 winmm Qt5WinExtras libEGL ws2_32 translator qtpcre libGLESv2 qtharfbuzzng preprocessor )

It works! But note the duplicated Qt5Gui in the early end of the line? If I take out either one and compile, I ended up with TONS of undefined reference link errors.

I wonder how can I figure out the correct order! Thanks!

2
  • In the older days, with some toolchains the simple trick of linking everything twice worked. Try to repeat the TARGET_LINK_LIBRARIES directive twice. Haven't tried it recently, can't be sure that it still works (and that it works with cmake).
    – Dummy00001
    Apr 8, 2016 at 11:34
  • You should be using the Qt support included with cmake - the linking of dependencies will be handled automatically. Aug 9, 2018 at 19:06

1 Answer 1

1

By trial-and-error, mostly... You could theoretically extract the external references from a library with nm (all the symbols with an 'U' or 'u' in the second column), then search for those symbols in other libraries and place them behind the first library in the link order. But that's more work than it's worth. The undefined references should give you a good hint as to which library you need.

The double Qt5Gui is probably because there are circular references between libraries (i.e. libA needs a function from libB, and libB references a function from libA). There's no harm in adding it twice; the linker is smart enough to only include the functions that it really needs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.