I am trying to build my Qt app with MinGW in QtCreator in order to try and debug a release-only crash.
Here is what I put in my .pro file (also tried putting it directly into qmake.conf):
QMAKE_CFLAGS_RELEASE += -g
QMAKE_CXXFLAGS_RELEASE += -g
QMAKE_CXXFLAGS += -g
as well as tried with
QMAKE_CFLAGS_RELEASE += -ggdb
QMAKE_CXXFLAGS_RELEASE += -ggdb
QMAKE_CXXFLAGS += -ggdb
I tried them separately or together like this:
QMAKE_CFLAGS_RELEASE += -g
QMAKE_CXXFLAGS_RELEASE += -g
QMAKE_CXXFLAGS += -g
QMAKE_CFLAGS_RELEASE += -ggdb
QMAKE_CXXFLAGS_RELEASE += -ggdb
QMAKE_CXXFLAGS += -ggdb
I have also manually edited the generated Makefile(Makefile.Release to be exact and checked Makefile.Debug just in case) to remove the NO_DEBUG flag (I don't know why it was being put there) and to make sure the -g and -ggdb flags are there.
The result of all of this is that the app took almost twice as long to build, however it was exactly the same size as before and didn't have any debugging symbols and trying to debug it didn't succeed.
What else can I do? I know it's possible, but looking for other answers only directed me to using those flags and that didn't help at all(only made build slower)
In qmake.conf (can't recall where this is now) the default behaviour is set as:
QMAKE_LFLAGS_RELEASE = -Wl,-s
Where the -s means the linker does away with the symbolic info. So in addition to the flags you have set you need to clear the flags (or overwrite) in QMAKE_LFLAGS_RELEASE. In your case just setting it to empty should do it, so in your .pro file add:
QMAKE_LFLAGS_RELEASE =
FURTHER NOTES
If you add the line message(QMAKESPEC: $$QMAKESPEC) to your .pro file, when you run qmake you will see the path for your make spec. Look in the qmake.conf file (it will have includes) and work your way through them.
Assuming you are using windows (because I did not see the -Wl,-s option set in the linux make specs for Qt 5.5.1) then the file in question is:
<path-to-qt>/5.5/gcc_64/mkspecs/win32-g++/qmake.conf
Anyway, I did not see any other useful flags set (I am using linux so this was only checked by eye. However if you are worried, then add the following to your .pro file:
message(QMAKE_LFLAGS_RELEASE: $$QMAKE_LFLAGS_RELEASE)
To check it before you make changes and then you will have the complete picture of what is going on :)
I've just figured it out, and only saw #code_fodder's answer after it. It looks like #code_fodder is essentially right, but I'm adding more details to reflect the precise steps that helped me.
I've specified qmake arguments in the Qt Creator project settings like this:
QMAKE_CXXFLAGS+=-g QMAKE_LFLAGS_RELEASE-=-Wl,-s
This essentially adds -g to the compiler flags and removes -Wl,-s from the linker flags (which strips all symbols). Then I ran qmake and did full rebuild. After that, debugging sort of worked—as you'd expect for a release build: jumping from line to line in a somewhat random fashion because of the optimizations, but at least it worked.
I'm using 32-bit Qt 5.5.1 with bundled MinGW on a 64-bit Windows 7 system, if that is of any help.
Related
I am trying to build a standalone Qt app without any DLLs needed. I recompiled Qt 5.4.1 statically. When I compile and run an application, it doesn't require any Qt DLLs, but it requires libgcc_s_dw2-1.dll instead. I have also edited my mkspecs before configuring and building Qt, I edited these values:
QMAKE_CFLAGS = -pipe -fno-keep-inline-dllexport -static -static-libgcc
QMAKE_CXXFLAGS = -pipe -fno-keep-inline-dllexport -static -static-libgcc -static-libstdc++
(added -static -static-libstdc++ and -static-libgcc)
I also added a QMAKESPECS environment variable.
When I build something using Qt, I can always see this options in the output, so I am sure that the mkspecs are applying.
When I build a non-Qt program with these options (-static -static-libgcc -static-libstdc++), it doesn't need any DLLs when I run it.
Can somebody help me?
I use Qt 5.4.1 and MinGW-w64 4.9.2
I solved my problem now. The problem was that although I edited the variable QMAKE_CXXFLAGS, it was still linking the standard libraries dynamically when linking the application itself, because it doesn't use this variable in the final step of the compilation. I only edited the mkspecs again and added the -static option to the variable QMAKE_LIBS and it works now, I have a standalone Qt application.
Where in Qt Creator do I pass arguments to a compiler?
It isn't really that obvious.
Depending on your build system it's either in your qmake project file(.pro, standard for new projects) or in one of the CMake files (CMakeLists.txt, used by KDE and several other projects).
Using .pro:
QMAKE_CXXFLAGS += -O2
Using CMake:
set( CMAKE_CXX_FLAGS "-g -Wall")
To add compiler flags, open your .pro file and add a line like this:
QMAKE_CXXFLAGS += -std=c++0x
For standard flags like debug vs. release etc. you should try to use the predefined qmake options (see QMake documentation) for the sake of platform and compiler-independency, as QMake will map them to the compiler-specific flags.
If your intention is to precompile some source code you can do like this:
/A/ In your .pro file you can add a line like this:
DEFINES += HOPLA
/B/ In you .cpp or .h file you can use it like this
#ifdef HOPLA
// Do something
#else
// Do something different
#endif
for C projects, add the following line in .pro file
QMAKE_CFLAGS += -std=c99
in the .pro file you can add variables which modify the make behavior for example, if you try to execute the following command:
g++ -Wall -I/usr/include/cppconn -o exe main.cpp -L/usr/lib -lmysqlcppconn
you must add the following lines in the .pro file
INCLUDEPATH += /usr/include/cppconn
LIBS += -L/usr/lib -lmysqlcppconn
Check the image below.
For more information on the available variables that QT IDE uses, you can visit the following link where they explain in more detail each one. Qt Documentation: Variables
As the elected answer points, for CMake based projects, you can edit the CMakeLists.txt and set the flags for the compiler, and for this case, I have a pictorial demonstration on how to add flags on QtCreator/CMake.
I wanted to add the '-pedantic' flag, which warns about extensions, without throwing errors while executing the program, and here's pictorial example of how to enable compiler flags on CMake while using QtCreator:
For more context:
On the example below, I'm setting the size of a Static Array at Runtime, something that is only possible with Variable-length Array feature, which is available at C99, but defined as optional feature starting from C11. Without -pedantic flag being available for the compiler, the warning would't be displayed after compiling the code.
There is a small project C++ (it has win32 code) that I need to build. It already has its Makefile. I was told to use MinGW. I have never used it before. I downloaded and installed the latest MinGW installer.
Then, I opened the MinGW shell and did make. The exe file was created. But when I try to run it I get libgcc_s_dw2-1.dll is missing! Why do I get this error? Shouldn't the exe be self-contained and run anywhere?
UPDATE
Here's more information, from the Makefile:
CC = g++
CCOPTIONS=-DWINDOWS -DFORCEINLINE -DMINGW -DSRTP_SUPPORT -D__EXPORT= -D_WIN32_WINNT=0x0501 -DNOMVS
setup.exe: setup.o common.o
$(CC) -ggdb -g -O0 -o $# setup.o common.o -mno-cygwin -mwindows -lwsock32 -lws2_32 -lwinmm -lgdi32 -lcomctl32 -lmapi32 -lVfw32
Whether or not the exe should be self-contained depends on how you built it. We need to see the commands that were executed, or post the makefile. But that DLL does not seem to be part of the current version of MinGW. Also, please clarify if you are actually doing this under cygwin, or if you added the tag by mistake.
Edit: A bit of googling seems like it has to do with the horrible "official" MinGW installation. Remove it, and download the Twilight Dragon build from http://tdm-gcc.tdragon.net and then rebuild completely. The "official" build is cr*p anyway - I don't know why anyone uses it.
If what you want to do is a stand alone application with MinGW, you should add -static to the linking options.
On a side note, if you're making a Win32 application, add the -mwindows option to the C++ compiler so it doesn't open a console together with your main window.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Configuring the GCC compiler switches in Qt, QtCreator, and QMake
I would like to use -O1 instead of -O2 in my makefile (CFLAGS and CXXFLAGS) for my Linux build. My understanding of how these makefiles are generated based on the .pro file is somewhat lacking. This is because the version of Qt combined with the version of G++ I am using has instabilities when -O2 is present.
Presently, I am running a replacement script, after I run qmake, which does this:
sed -i 's/\-O2/\-O1/g' AllProjects/Makefile.Release
This is a ghetto solution. A much better solution would be to modify the .pro file somehow to pass along these directives. I am not sure how CFLAGS and CXXFLAGS are being generated though.
I have tried passing a
linux-g++-{
CFLAGS += -O1
CXXFLAGS += -O1
CONFIG += -O1
}
which did not work.
You were very close. What you want is:
QMAKE_CXXFLAGS += -O1
If you would like to apply flags to just the release build, then you can use this:
QMAKE_CXXFLAGS_RELEASE += -O1
You also probably want to change your condition to be a little more flexible. In summary, something like this:
*-g++* {
QMAKE_CXXFLAGS += -O1
}
More in the documentation here: http://qt-project.org/doc/qt-5.0/qtdoc/qmake-variable-reference.html#qmake-cxxflags
I am trying to obtain code coverage for a component I am writing for the Arora browser, that is written using C++ and Qt framework.
I am not able to use the gcov program, neither under Gnu/Linux nor Mac Os X. I tried everything I was able to find on the Internet, also by forcing things automatically editing the Makefile generated by the .pro file.
Can somebody help me please? This is my very simple pro file:
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
LIBS += -lgcov
QMAKE_CXXFLAGS += -g -fprofile-arcs -ftest-coverage -O0
QMAKE_LDFLAGS += -g -fprofile-arcs -ftest-coverage -O0
include(../autotests.pri)
# Input
SOURCES += tst_quickview.cpp
HEADERS +=
The Makefile does correctly contain the flags. I also tried the --coverage option. But nothing happens. When I run the executable, no gcov files are generated. There are no errors and no warnings. I am using the QTestLib framework.
Thank you
Atleast in cases where i've had similar issues, the problem has been in directory structures.
First issue was/is that in order to generate proper .gc* files during execution, compiler cache needs to be disabled. I never really debugged the issue but now, i'd assume that the gconv files where infact placed on the compiler cache folder and during the execution of the coverage instrumented binaries, binary was not able to idenfify where new datafiles should be generated.
Second issue is/was that i had to run the tests in the same directory structure as they where compiled in. For example, if i had compiled the application in "/home/foo/src/myproject/" and all its subdirectories .. The execution has to happen in that same directory structure or the datafiles won't get generated..
At least you should use
QMAKE_LFLAGS += -g -fprofile-arcs -ftest-coverage -O0
instead of
QMAKE_LDFLAGS += -g -fprofile-arcs -ftest-coverage -O0
I'm not sure if that will fix your problem but QMAKE_LDFLAGS is not going to do anything useful.