14

I'm absolutely new to Qt. I've made a program using C++ in Visual Studio 2010 in which I use the external library from Dcmtk. I now want to add a user interface to that program. In my original program I had to change the C++ Runtime Library in Code Generation setting in Visual Studio to Multi-Threaded(/MT) from Multi-Threaded Debug DLL otherwise the program would not work. I have to do the same in QtCreator, but I don't know how to change that setting in Qt. Could you please suggest how I should approach that? Thanks.

the_naive
  • 2,936
  • 6
  • 39
  • 68

4 Answers4

10

/MT is a compiler flag. You can specify flags in your .pro file like this:

QMAKE_CXXFLAGS += /MT

Moreover, you probably want to specify /MTd for debug build:

Release:QMAKE_CXXFLAGS += /MT
Debug:QMAKE_CXXFLAGS += /MTd
Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335
5

In the version of QT 5.5 the variable is QMAKE_CXXFLAGS_DEBUG and QMAKE_CXXFLAGS_RELEASE so the new working solution for QT 5.5 is:

QMAKE_CXXFLAGS_DEBUG += /MTd
QMAKE_CXXFLAGS_RELEASE += /MT
nicksona
  • 326
  • 2
  • 13
0

A qmake configuration is also available for this.

CONFIG += thread
Funmungus
  • 134
  • 1
  • 4
0

since Qt 5, adding to your qmake build script *.pro file, a configuration like:

CONFIG += static_runtime

will cause qmake to include the mkspecs/features/static_runtime.prf file, which should contain the required configurations, something like below:

msvc {
    # -MD becomes -MT, -MDd becomes -MTd
    QMAKE_CFLAGS ~= s,^-MD(d?)$, -MT\1,g
    QMAKE_CXXFLAGS ~= s,^-MD(d?)$, -MT\1,g
} else: mingw {
    QMAKE_LFLAGS += -static
}

but as advance warning, note that this may cause some link errors, which make an statement like "MSVCRT.lib(MSVCRxxx.dll) : error LNK2005: xxx already defined in LIBCMTD.lib(xxx.obj)", basically because other libraries that you are using are linked with the dynamic CRT library (i.e. they are NOT build with /MT or /MTd flag, and you would need to rebuild them with the appropriate flag), for more see this question.

Top-Master
  • 7,611
  • 5
  • 39
  • 71