Cannot compile a simple Qt program in MT mode as opposed to MD in Visual Studio 2010

后端 未结 3 1928
暗喜
暗喜 2020-12-31 11:32

I\'m trying to compile using MTd in Visual Studio 2010 instead of MDd (so that the dll\'s are packaged in and i won\'t need to distribute them with my exe), but I keep getti

相关标签:
3条回答
  • 2020-12-31 11:36

    This is a standard linker error when you tinker with /MT. You are now linking some code that was compiled with /MT and thus has a dependency on the CRT code in libcmt.lib with some code that was compiled with /MD and thus has a dependency on the CRT code in msvcrt.lib. This is not allowed, there can be only one CRT linked into your program.

    You'll need to find the code that is still compiled with /MD. This code may well exist in a .lib, like the runtime support code for QT. If QT doesn't have a .lib that supports statically linking the CRT then you're stuck with /MD. That's not uncommon, writing code that lives in DLLs that can deal with /MT is difficult.

    0 讨论(0)
  • 2020-12-31 11:44

    you may rebuild QT to use static VC libraries. Go to ${QtDir}\mkspecs\win32-msvc2010\qmake.conf, and replace

    QMAKE_CFLAGS_RELEASE    = -O2 -MD
    QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi
    QMAKE_CFLAGS_DEBUG      = -Zi -MDd
    

    with

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

    after that clean reconfigure and rebuild qt

    0 讨论(0)
  • 2020-12-31 11:50

    You are linking your program statically and linking against libcmt, but at the same time, linking in code from the Qt DLLs, which are, as the name already says, dynamically linked against msvcrt.lib.

    You will need to either link dynamically or recompile Qt from source as static, which isn't hard, but time-consuming.

    0 讨论(0)
提交回复
热议问题