Static Qt with static MSVC C++ library



  • Hi,

    I am compiling an application statically with no problem but I would like to use the static version of the MSVC C++ library. To do so I use:
    QMAKE_CFLAGS_RELEASE += /MT
    QMAKE_CXXFLAGS_RELEASE += /MT

    But I get multiple definitions of the same symbol:
    ...
    MSVCRT.lib(MSVCR100.dll) : error LNK2005: __open_osfhandle already defined in LIBCMT.lib(osfinfo.obj)

    Is there an easy solution or should I tell the linker to accept multiple symbols?


  • Moderators

    Since you are refering to MSVC C++ I would assume that you are also using visual studio. You could install "vsaddin ":http://developer.qt.nokia.com/wiki/QtVSAddin
    There is no need to use qmake explicitely.



  • One way or the other the actual flag to accept multiple symbols is:
    QMAKE_LFLAGS_RELEASE += /FORCE:MULTIPLE

    But it still creates an executable relying on:
    MSVCP100.dll
    MSVCR100.dll

    And I would like to get rid of those DLL dependencies.


  • Moderators

    I have just compiled a small project with /MT option. I was compiling with dlls before.
    First recompilation it complaint that I need to specify /NODEFAULTIB
    Second recompilation gave loads of error messages. Probable I would need to adjust more settings, which I can't do today.

    BTW: I am using Win 7 64 bit and msvc2005.



  • Any luck?



  • It looks like with MSVC you need to tell at compile-time DLL or LIB dependencies. This means you need to rebuild QT to use static VC libraries. Go to ${QtDir}\mkspecs\win32-msvc2010\qmake.conf, and replace

    QMAKE_CFLAGS_RELEASE = -O2 -MD
    QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi
    QMAKE_CFLAGS_DEBUG = -Zi -MDd

    with

    QMAKE_CFLAGS_RELEASE = -O2 -MT
    QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MT -Zi
    QMAKE_CFLAGS_DEBUG = -Zi -MTd


  • Moderators

    I was able to setup a small "hello world" application with -MT. When I add Qt it will require dlls, because I do not have a static Qt compilation. So, that is logical.
    Did you succeed with your application?



  • I need to rebuild the Qt libraries using the settings previously mentioned, so it'll take me another 2 hours. I might as well add the following compilation flag: /Gy and link the final executable with /OPT:REF. This way it'll remove unused functions. And voila!



  • Just for the records I found a nmake clone that uses all the available cores on the system... just like "-jX" of make:
    http://labs.qt.nokia.com/2009/03/27/speeding-up-visual-c-qt-builds/


  • Moderators

    [quote author="philippeb8" date="1310852943"]Just for the records I found a nmake clone that uses all the available cores on the system... just like "-jX" of make:
    http://labs.qt.nokia.com/2009/03/27/speeding-up-visual-c-qt-builds/[/quote]

    Yes, jom may reduce your overall compilation time cosiderably.


  • Moderators

    [quote author="philippeb8" date="1310747680"]
    MSVCRT.lib(MSVCR100.dll) : error LNK2005: __open_osfhandle already defined in LIBCMT.lib(osfinfo.obj)

    Is there an easy solution or should I tell the linker to accept multiple symbols?[/quote]
    As answer to your initial question: You may also exclude LIBCMT (option: NODEFAULTLIB:LIBCMT). This is eliminating the multiple definitions warning/error.

    However, for msvc2005 there is an error:
    @
    error LNK2019: unresolved external symbol _WSAAsyncSelect@16 referenced in function "public: void __thiscall EventDispatcherWin32Private::doWsaAsyncSelect(int)" (?doWsaAsyncSelect@QEventDispatcherWin32Private@@QAEXH@Z)
    @
    This error is there also when LIBCMT has not been ignored, respectively, also accepting multiple definitions does not help. Could be an msvc2005 specific problem.


Log in to reply
 

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