How do I change the Runtime Library setting in my project in QtCreator?
-
@chadw
So then you should have just two requirements to meet:-
Whatever flags you compile your code with must match the flags for whatever the existing downloaded libraries you wish to link against were compiled with. If
/MT
is for multi-threaded and/MD
is not, given that Qt is heavily multi-threaded I wonder if you need the former. -
Your own code must be consistently & completely compiled with same flags. Especially in the case that you have changed the flags in your
.pro
file, I think you should absolutely clean out all your existing.obj
files etc. and ensure you do do a completely fresh rebuild and try again.
-
-
@JonB Actually, looking in Visual Studio, all four options appear to be multi-threaded:
But I take your point for 1), they must agree across all projects.
For 2), I've got a bigger issue. I can't change the value in the .obj files through QtCreator. In VStudio, I can change it using the project properties, rebuild and look in any resulting .obj file. Using the link in my original post, I though the syntax for setting Runtime Library was:
QMAKE_CFLAGS_DEBUG += /MT
or possibly
QMAKE_CFLAGS_RELEASE += /MT
But this doesn't change the built .obj files. I've got the /debug folder open on my second monitor, so I can see object files disappear when I clean the project and reappear when I build it. Is QMAKE_CFLAGS_DEBUG overridden elsewhere, or am I use the wrong flag?
-
@JonB Ahh, thank you for trying though.
On a wider note, changing the
QMAKE_CFLAGS_RELEASE
orQMAKE_CFLAGS_DEBUG
flag as I mentioned above doesn't seem to change what ends up inside the different object files. But examining the object (and ProcessingLib.lib) files, I noticed they all have the same settings across both projects.Looking at the first linker error:
ProcessingLib.lib(processingdefinition.obj):-1: error: LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in main.obj
Looking inside ProcessingLib/debug/ProcessingLib.lib, I see:
/FAILIFMISMATCH:"_MSC_VER=1900" /FAILIFMISMATCH:"_ITERATOR_DEBUG_LEVEL=2" /FAILIFMISMATCH:"RuntimeLibrary=MDd_DynamicDebug" /DEFAULTLIB:"msvcprtd" /FAILIFMISMATCH:"_CRT_STDIO_ISO_WIDE_SPECIFIERS=0" /DEFAULTLIB:"MSVCRTD" /DEFAULTLIB:"OLDNAMES"
Inside ProcessingLib/debug/pixelprocessor.obj:
/FAILIFMISMATCH:"_MSC_VER=1900" /FAILIFMISMATCH:"_ITERATOR_DEBUG_LEVEL=2" /FAILIFMISMATCH:"RuntimeLibrary=MDd_DynamicDebug" /DEFAULTLIB:"msvcprtd" /FAILIFMISMATCH:"_CRT_STDIO_ISO_WIDE_SPECIFIERS=0" /DEFAULTLIB:"MSVCRTD" /DEFAULTLIB:"OLDNAMES"
Inside ProcessingLibTest/debug/main.obj:
/FAILIFMISMATCH:"_MSC_VER=1900" /FAILIFMISMATCH:"_ITERATOR_DEBUG_LEVEL=0" /FAILIFMISMATCH:"RuntimeLibrary=MDd_DynamicDebug" /DEFAULTLIB:"msvcprtd" /FAILIFMISMATCH:"_CRT_STDIO_ISO_WIDE_SPECIFIERS=0" /DEFAULTLIB:"MSVCRTD" /DEFAULTLIB:"OLDNAMES"
In short, RuntimeLibrary=MDd_DynamicDebug, is in violent agreement across the files. The plot thickens.
(PS. For those who spot above that
_ITERATOR_DEBUG_LEVEL
differ - I took care of that Linker error by:#define _HAS_ITERATOR_DEBUGGING 0
in the complaining header files of ProcessingLibTest) -
@chadw said in How do I change the Runtime Library setting in my project in QtCreator?:
On a wider note, changing the QMAKE_CFLAGS_RELEASE or QMAKE_CFLAGS_DEBUG flag as I mentioned above doesn't seem to change what ends up inside the different object files.
Just a very quick one: I'm not sure the type of flags you were mentioning changing --- e.g.
/MD
->/MT
--- would necessarily have much/any effect on a.obj
file's size/content. If the only difference is that it changes which library the.obj
links with, which may be the case for that example, you might not see much change. -
@JonB If I change the RunTime Library option in Visual Studio[1], the
RuntimeLibrary
setting in the object files change accordingly. My assumption was that setting the relevantQMAKE_CFLAGS_
flag ough to do the same. But as it doesn't change that entry in the object files, my syntax is somehow wrong. Or it's overwritten somewhere else. Or I've got the wrong end of the stick (not for the first time).
[1] Project Properties -> Configuration Properties -> C/C++ -> Code Generation, Runtime Library
-
@chadw
(I use VS 2010, though not for Qt, so my interface may be a bit different from yours.)Suggestion:
When you change your settings in VS, have a look at what VS is actually doing to the command-line, both for compilation & linking. For example, in VS 2010 I have:- Configuration Properties > C/C++ > Command Line
- Configuration Properties > Linker > Command Line
Maybe it's making an explicit change to the linker command to account for your change, in addition to the
/MDd
? -
@JonB Thank you for persevering with me - I finally managed to figure it out. I was using the wrong variable in the end. It should be:
QMAKE_CXXFLAGS_DEBUG
With this in place, i.e. for instance changing it with:
QMAKE_CXXFLAGS_DEBUG += /MDd
I was being told that my new setting was being overridden:
But courtesy of the pointer of a SO post, I went into my Makefile.Debug file and hacked the relevant line as suggested by:
https://stackoverflow.com/a/25317701/2903608
Although now, QtCreator appear to honour whatever I set using
QMAKE_CXXFLAGS_DEBUG
, without needing to hack the makefile to avoid my setting being overwritten.
For clarity, it's the
CXXFLAGS
line in the Makefile.Debug that I initially (but no longer..) needed to modify.