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

前端 未结 4 1422
小蘑菇
小蘑菇 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: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.

提交回复
热议问题