July 15, 2011

philippeb8 philippeb8
Lab Rat
19 posts

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?

10 replies

July 15, 2011

koahnig koahnig
Mad Scientist
2193 posts

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

July 15, 2011

philippeb8 philippeb8
Lab Rat
19 posts

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.

July 15, 2011

koahnig koahnig
Mad Scientist
2193 posts

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.

July 16, 2011

philippeb8 philippeb8
Lab Rat
19 posts

Any luck?

July 16, 2011

philippeb8 philippeb8
Lab Rat
19 posts

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

July 16, 2011

koahnig koahnig
Mad Scientist
2193 posts

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?

July 16, 2011

philippeb8 philippeb8
Lab Rat
19 posts

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!

July 16, 2011

philippeb8 philippeb8
Lab Rat
19 posts

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/

July 17, 2011

koahnig koahnig
Mad Scientist
2193 posts
philippeb8 wrote:
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/

Yes, jom may reduce your overall compilation time cosiderably.

July 17, 2011

koahnig koahnig
Mad Scientist
2193 posts

philippeb8 wrote:

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?


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:

  1. 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.

 
  ‹‹ mysql for Qt on ubuntu      [Solved] How to uninstall Qt SDK from Mac OS ››

You must log in to post a reply. Not a member yet? Register here!