setting linker options in qt5

3.6k views Asked by At

I compiled qt 5.5.1 statically using the following options:

configure -static -release -platform win32-msvc2013

and now when I am trying to compile a simple hello world program that doesn't use any qt libraries (just plain c++ app).

The problem is that I can't set the linker options for the program to use static msvc libraries using the /MT flag. I am adding this to project file:

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

I get the following error:

msvcprt.lib(locale0_implib.obj):-1: error: LNK2038: mismatch detected for     'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj

and

:-1: warning: LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
3

There are 3 answers

0
Farahats9 On BEST ANSWER

I figured it out, the clean command didn't delete the MAKEFILE.RELEASE so I had to go delete the file manually and qmake generated a new file with correct -MT parameter. Thanks for all the help.

2
Vladislav Mikitich On
QMAKE_CXXFLAGS_RELEASE += -O2 -MT
QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MT -Zi
QMAKE_CXXFLAGS_DEBUG += -Zi -MTd

also you can try

LIBS += -lLIBRARY /NODEFAULTLIB:library
1
gzh On

If my memory serve me correctly, this is a problem you will meet also frequently when you use visual studio. So modify the build configuration as shown in the warning message, add NODEFAULTLIB preprocessor in build command please.