How do I change the Runtime Library setting in my project in QtCreator?
-
Apologies for being vague - I did not build from source (just edited original post to clarify that). I installed the binary downloaded from Qt.
There are two libraries (inherited from a colleague). ProcessingLib processes pixel data, the second project (ProcessingLibTest) is a basic Gui allowing the user to select some processing options, file(s) to be processed, where to save processed files etc.
Running ProcessingLibTest.exe built as Release works fine. I was told my colleague never got the executable built as Debug to work. However, this does not seem impossible to me (although I am having linker issues). The runtime library setting of ProcessingLib was /MDd, for ProcessingLibTest it was also /MDd. Building the library as Debug was fine but building the executable as Debug produce the linker errors (ie: value of MD_DynamicRelease not matching value of MDd_DynamicDebug).
If I change ProcessingLibTest from /MDd to /MD, I can build the ProcessingLibTest executable as Debug.
However, 2 things strike me here. First, if both project are built with /MDd, why are they disagreeing? There are other libraries/DLLs involved (some custom written for this project), so could they be a factor? Only, the linker errors complain about ProcessingLib's classes, not libraries, etc beyond it..?
Secondly, why do I have to change The Runtime Library of the executable class (to apparently disagree with ProcessingLib's setting) to get things building?
I have been programming for years but not spent nearly as much time on "properly" debugging C++ code, such as running the debugger, loading symbol (PDB) files and the like. So this is a bit of a learning curve for me.
-
@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.