How to change the C++ Runtime Library setting in QtCreator?

前端 未结 4 1378
小蘑菇
小蘑菇 2021-01-08 00:47

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 pr

相关标签:
4条回答
  • 2021-01-08 01:23

    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
    
    0 讨论(0)
  • 2021-01-08 01:28

    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.

    0 讨论(0)
  • 2021-01-08 01:41

    /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
    
    0 讨论(0)
  • 2021-01-08 01:41

    A qmake configuration is also available for this.

    CONFIG += thread
    
    0 讨论(0)
提交回复
热议问题