Problems with shadow builds and static release linkage



  • Hello,

    I'd like to have multiple builds of qt, configured differently.
    I'm using Visual Studio 2013 for that.

    My plan is:
    \build_dev as debug shared
    \build_app1 as release static
    etc.

    \build_dev\qtbase\bin is in my PATH, and \build_app1\qtbase would be added as a new Qt version to the Qt Add-in.

    In \build_app1\qtbase for example, I created the symlinks bin, include and mkspecs pointing to \build_dev\... (and also symlinks for the debug import .libs). That way, applications built in debug mode should use dynamic linking and in release mode, they should use \build_app1 etc. and static linking.

    Debug build works fine, but when I try to build in release, I get these linker errors:

    moc_MainWindow.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static struct QMetaObject const QMainWindow::staticMetaObject" (__imp_?staticMetaObject@QMainWindow@@2UQMetaObject@@B)
    ...
    Main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall QApplication::QApplication(int &,char * *,int)" (__imp_??0QApplication@@QAE@AAHPAPADH@Z)
    ...
    MainWindow.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static struct QMetaObject const QAbstractButton::staticMetaObject" (__imp_?staticMetaObject@QAbstractButton@@2UQMetaObject@@B)

    Does the Visual Studio add-in even support creating an app with static Qt linkage?
    Or is it a problem with my shadow builds and the folder structure I have?

    What I found is that if I link with QtWidgetsd.lib, these errors go away! But it's a release build, how can that be?
    I checked Qt5Widgets.lib from the static release build and found the symbol ?staticMetaObject@QMainWindow@@2UQMetaObject@@B (without __imp _), then I checked QtWidgetsd.lib from the dynamic debug build and found __imp_?staticMetaObject@QMainWindow@@2UQMetaObject@@B.

    What is going on here?

    I really hope someone can help me... I've been working the last 2 days on this with little sleep to get this working :(

    Thank you!



  • This post is deleted!


  • Whew! I think I got it...

    The mistake was to use the includes of shared \build_dev when building in release.
    There is only one little difference which made everything work: qconfig.h!
    It defines QT_STATIC in the static \build_app1 ...

    The debug config of the project created by the Qt Add-in has to be adjusted a little though:
    Include directory $(QTDIR$)\include =>...\build_dev\qtbase\include.
    Lib directory $(QTDIR$)\lib =>...\build_dev\qtbase\lib.
    The project still uses \build_app1\qtbase as Qt Version.

    That way, the Debug build looks for includes and libs in \build_dev while the Release build looks in \build_app1.
    And the .lib symlinks are not necessary anymore, I just kept the bin directory symlink.

    Just in case someone else wants to do something like this...



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.