1

I'm developing a native C++ application using Qt 4.8.3 and VS2008. Since clients run the application on their naked machines, they need to install VC++ 2008 Redistribution package. So I decided to make it statically linked.

I changed my project settings (C/C++ > Code Generation > Runtime Library) to /MTd. Also I compiled Qt again, this time using following commands for a static building; originally found on this blog Static Qt with static CRT (VS 2008)

1- replaced -MD with -MT in lines QMAKE_CFLAGS_RELEASE and QMAKE_CFLAGS_DEBUG in %QDIR%\mkspecs\win32-msvc2008\qmake.conf
2- nmake confclean 
3- configure -static -platform win32-msvc2008 -no-webkit 
4- nmake sub-src

I compiled Qt successfully. But when I tried again to compile my application, it gave me some strange errors.

1>Linking...
1>qtmaind.lib(qtmain_win.obj) : error LNK2005: "public: bool __thiscall QBasicAtomicInt::deref(void)" (?deref@QBasicAtomicInt@@QAE_NXZ) already defined in QtCored4.lib(QtCored4.dll)
1>qtmaind.lib(qtmain_win.obj) : error LNK2005: "public: bool __thiscall QBasicAtomicInt::operator!=(int)const " (??9QBasicAtomicInt@@QBE_NH@Z) already defined in QtCored4.lib(QtCored4.dll)
1>qtmaind.lib(qtmain_win.obj) : error LNK2005: "public: __thiscall QString::~QString(void)" (??1QString@@QAE@XZ) already defined in QtCored4.lib(QtCored4.dll)

I changed some lib files but with each change, situation got worse; for example I tried to use QtCored.lib instead of QtCored4.lib because it is newly created after compilation.

I think I've missed something in building static Qt libs.

1 Answer 1

0

Although this question has remained unanswered since late 2012, I thought it might be a good idea to further populate the general knowledge on this issue in order for each thread to display at least one response.

The problem stems from the inclusion of the QtCored4.dll and QtGuid4.dll during the link process when building Qt statically. To exclude these from the build process, simply add QT_NODLL as a preprocessor directive when configuring Makefile. For instance, this may be achieved using the following command (for Microsoft Visual Studio 2008):

configure -static -debug -D QT_NODLL -platform win32-msvc2008 

prior to running NMAKE.

A good practice when building static Qt applications using the Visual Studio IDE is to modify the project configuration type to Makefile using the Configuration Properties->General->Configuration Type drop-down menu. Once these settings have been applied, the user may also specify qmake and nmake steps to perform for Build and Rebuild All options under Configuration Properties->General->NMake.

For instance the build command-line for static debug configuration would be:

nmake debug

And the rebuild-all equivalent:

qmake app_debug.pro && nmake debug

I hope this helps!

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.