CMake + qtcreator + MinGW +调试模式+ Windows 7。

时间:2022-06-16 20:28:26

I use CMake with VC++ under windows 7 and everything works fine. Now, I want to test qtcreator but I cannot force debug flags. I am using MinGW generator with cmake and adding -DCMAKE_BUILD_TYPE=Debug on the command line.

我在windows 7下使用CMake和vc++,一切正常。现在,我想测试qtcreator,但是我不能强制调试标志。我使用的是cmake的MinGW生成器,并在命令行中添加-DCMAKE_BUILD_TYPE=Debug。

I can use CMake feature from inside QTCreator to generate projects with -DCMAKE_BUILD_TYPE=Debug. It compiles just fine and I can run it. However, I cannot debug it as QTCreator complains it is not a "debuggable executale". I also tried generating the projects directly using the command line.

我可以在QTCreator中使用CMake特性来生成带有-DCMAKE_BUILD_TYPE=Debug的项目。它编译的很好,我可以运行它。但是,我不能调试它,因为QTCreator抱怨它不是一个“可调试的执行器”。我还尝试使用命令行直接生成项目。

What am I doing wrong?

我做错了什么?

4 个解决方案

#1


1  

I think you did nothing wrong.

我想你没有做错什么。

When using MSVC in Debug mode, debug symbols (*.pdb files) are generated in the same folder than your built binary. They can be used later to debug you application.

在调试模式下使用MSVC时,调试符号(*。在同一个文件夹中生成pdb文件,而不是生成的二进制文件。它们可以稍后用于调试应用程序。

When using MingW, no additional file is generated. When you configure a CMAKE_BUILD_TYPE to Debug or RelWithDebInfo, the option -g is added to the compilation command line. This produce debug information inside the binary. Then, you will be able to debug your program with GDB (you can try it in Qt Creator, it works ;))

在使用MingW时,不会生成其他文件。当您将CMAKE_BUILD_TYPE配置为Debug或RelWithDebInfo时,将选项-g添加到编译命令行中。这将在二进制文件中生成调试信息。然后,您将能够使用GDB调试您的程序(您可以在Qt创建者中尝试它,它可以工作;))

You can verify this by changing CMAKE_BUILD_TYPE values and check the size of your resulting binary. I just test for one of my projects:

您可以通过更改CMAKE_BUILD_TYPE值并检查生成的二进制文件的大小来验证这一点。我只是测试我的一个项目:

CMAKE_BUILD_TYPE                      Executable size
<empty>                                   1890 Ko
Release                                   1281 Ko
Debug                                    14743 Ko
MinSizeRel                                1027 Ko
RelWithDebInfo                           15859 Ko

#2


2  

It's hard to figure out what's wrong so I'll give you a few hints:

很难弄清楚到底出了什么问题,所以我会给你一些提示:

  1. Set CMAKE_VERBOSE_MAKEFILE in CMakeChace.txt file and run cmake again. Then call make clean and make. Then examine output and check what flags are being passed to compiler.

    设置在CMakeChace CMAKE_VERBOSE_MAKEFILE。txt文件并再次运行cmake。然后叫“清洁”和“制造”。然后检查输出并检查传递给编译器的标志。

  2. Check CMakeCache.txt file for flags which are passed to compiler for particular builds. Check if -g and -O0 are passed for debug mode.

    检查CMakeCache。用于为特定的构建传递给编译器的标记的txt文件。检查是否将-g和-O0传递给调试模式。

  3. Try to build a very simple program and compile it manually with -g and -O0. Then try to debug it with gdb and QtCreator (as external application) and check if that's a problem with QtCreator itself or your compiler options.

    尝试构建一个非常简单的程序,并用-g和-O0手工编译它。然后尝试用gdb和QtCreator(作为外部应用程序)调试它,并检查这是否是QtCreator本身或编译器选项的问题。

#3


2  

I run into this problem today just like you. Most likely you are using VS CDB instead of GDB.

我今天遇到了这个问题,就像你一样。很可能你使用的是vcdb而不是GDB。

Here is my solution:

这是我的解决方案:

(0) download MinGW and GCC from http://mingw-w64.sourceforge.net/index.php

(0)从http://mingw64.sourceforge.net/index.php下载MinGW和GCC。

(1) set environment variable, so Qt-creator can auto detect MinGW and GCC

(1)设置环境变量,因此Qt-creator可以自动检测MinGW和GCC。

set MINGW_DIR add %MINGW_DIR% to PATH

设置MINGW_DIR添加%MINGW_DIR%到路径。

(2) re-start Qt-creator

(2)重启qt creator

open Qt-creator -> tools->options->Build&Run->kits

开放的qt creator - >工具- >选项- >构建和运行- >工具

add manually "MinGW-GCC" (or other name you like)

手动添加“MinGW-GCC”(或您喜欢的其他名称)

check compiler, gcc should be auto detected

检查编译器,gcc应该自动检测。

set Debugger ->Edit : GDB Engine and choose the folder of gdb.exe

设置调试器->编辑:GDB引擎,选择GDB .exe文件夹。

Make sure that CDB is not used

确保不使用CDB。

#4


0  

I'm not too familiar with QtCreator, but I'll try to help by explaining what I used to generate makefiles for Eclipse CDT4 (which may be another option for you to try as a Windows IDE).

我对QtCreator不太熟悉,但是我会试着解释我用来生成Eclipse CDT4的makefile(这可能是您尝试使用Windows IDE的另一种选择)。

First, are you sure your cmake can generate QtCreator makefiles? I ask because at least on Fedora, cmake doesn't list Qtcreator as an option.

首先,您确定您的cmake可以生成QtCreator makefile吗?我问,因为至少在Fedora上,cmake不把Qtcreator作为选项。

Typing "cmake" on the command line should list the generators available for your platform. Is QtCreator one of them?

在命令行上键入“cmake”,应该列出您的平台可用的生成器。QtCreator是其中之一吗?

Second, it is quite possible that cmake just doesn't have that option for your compiler. This does not necessarily mean that you won't be able to debug code from that compiler. For example, I generated files for Eclipse CDT without setting the debug flags, but am still able to debug just fine.

第二,cmake很有可能对编译器没有这个选项。这并不一定意味着您无法从该编译器中调试代码。例如,我在没有设置调试标志的情况下为Eclipse CDT生成了文件,但是仍然能够调试好。

For reference, here is the list of commands I used for Eclipse CDT (from the project root dir, the cmakelists.txt file is in the src subdirectory):

作为参考,这里是我用于Eclipse CDT的命令列表(从项目根目录,cmakelists)。txt文件在src子目录中):

mkdir eclipse-project
cd eclipse-project
cmake ../src -G "Eclipse CDT - Unix Makefiles"

Then I can open the project from Eclipse and debug. I suspect you'll be able to do the same, whether cmake knows how to enable debug for your compiler or not.

然后,我可以从Eclipse和debug打开这个项目。我猜您也可以这样做,cmake是否知道如何为编译器启用调试。

#1


1  

I think you did nothing wrong.

我想你没有做错什么。

When using MSVC in Debug mode, debug symbols (*.pdb files) are generated in the same folder than your built binary. They can be used later to debug you application.

在调试模式下使用MSVC时,调试符号(*。在同一个文件夹中生成pdb文件,而不是生成的二进制文件。它们可以稍后用于调试应用程序。

When using MingW, no additional file is generated. When you configure a CMAKE_BUILD_TYPE to Debug or RelWithDebInfo, the option -g is added to the compilation command line. This produce debug information inside the binary. Then, you will be able to debug your program with GDB (you can try it in Qt Creator, it works ;))

在使用MingW时,不会生成其他文件。当您将CMAKE_BUILD_TYPE配置为Debug或RelWithDebInfo时,将选项-g添加到编译命令行中。这将在二进制文件中生成调试信息。然后,您将能够使用GDB调试您的程序(您可以在Qt创建者中尝试它,它可以工作;))

You can verify this by changing CMAKE_BUILD_TYPE values and check the size of your resulting binary. I just test for one of my projects:

您可以通过更改CMAKE_BUILD_TYPE值并检查生成的二进制文件的大小来验证这一点。我只是测试我的一个项目:

CMAKE_BUILD_TYPE                      Executable size
<empty>                                   1890 Ko
Release                                   1281 Ko
Debug                                    14743 Ko
MinSizeRel                                1027 Ko
RelWithDebInfo                           15859 Ko

#2


2  

It's hard to figure out what's wrong so I'll give you a few hints:

很难弄清楚到底出了什么问题,所以我会给你一些提示:

  1. Set CMAKE_VERBOSE_MAKEFILE in CMakeChace.txt file and run cmake again. Then call make clean and make. Then examine output and check what flags are being passed to compiler.

    设置在CMakeChace CMAKE_VERBOSE_MAKEFILE。txt文件并再次运行cmake。然后叫“清洁”和“制造”。然后检查输出并检查传递给编译器的标志。

  2. Check CMakeCache.txt file for flags which are passed to compiler for particular builds. Check if -g and -O0 are passed for debug mode.

    检查CMakeCache。用于为特定的构建传递给编译器的标记的txt文件。检查是否将-g和-O0传递给调试模式。

  3. Try to build a very simple program and compile it manually with -g and -O0. Then try to debug it with gdb and QtCreator (as external application) and check if that's a problem with QtCreator itself or your compiler options.

    尝试构建一个非常简单的程序,并用-g和-O0手工编译它。然后尝试用gdb和QtCreator(作为外部应用程序)调试它,并检查这是否是QtCreator本身或编译器选项的问题。

#3


2  

I run into this problem today just like you. Most likely you are using VS CDB instead of GDB.

我今天遇到了这个问题,就像你一样。很可能你使用的是vcdb而不是GDB。

Here is my solution:

这是我的解决方案:

(0) download MinGW and GCC from http://mingw-w64.sourceforge.net/index.php

(0)从http://mingw64.sourceforge.net/index.php下载MinGW和GCC。

(1) set environment variable, so Qt-creator can auto detect MinGW and GCC

(1)设置环境变量,因此Qt-creator可以自动检测MinGW和GCC。

set MINGW_DIR add %MINGW_DIR% to PATH

设置MINGW_DIR添加%MINGW_DIR%到路径。

(2) re-start Qt-creator

(2)重启qt creator

open Qt-creator -> tools->options->Build&Run->kits

开放的qt creator - >工具- >选项- >构建和运行- >工具

add manually "MinGW-GCC" (or other name you like)

手动添加“MinGW-GCC”(或您喜欢的其他名称)

check compiler, gcc should be auto detected

检查编译器,gcc应该自动检测。

set Debugger ->Edit : GDB Engine and choose the folder of gdb.exe

设置调试器->编辑:GDB引擎,选择GDB .exe文件夹。

Make sure that CDB is not used

确保不使用CDB。

#4


0  

I'm not too familiar with QtCreator, but I'll try to help by explaining what I used to generate makefiles for Eclipse CDT4 (which may be another option for you to try as a Windows IDE).

我对QtCreator不太熟悉,但是我会试着解释我用来生成Eclipse CDT4的makefile(这可能是您尝试使用Windows IDE的另一种选择)。

First, are you sure your cmake can generate QtCreator makefiles? I ask because at least on Fedora, cmake doesn't list Qtcreator as an option.

首先,您确定您的cmake可以生成QtCreator makefile吗?我问,因为至少在Fedora上,cmake不把Qtcreator作为选项。

Typing "cmake" on the command line should list the generators available for your platform. Is QtCreator one of them?

在命令行上键入“cmake”,应该列出您的平台可用的生成器。QtCreator是其中之一吗?

Second, it is quite possible that cmake just doesn't have that option for your compiler. This does not necessarily mean that you won't be able to debug code from that compiler. For example, I generated files for Eclipse CDT without setting the debug flags, but am still able to debug just fine.

第二,cmake很有可能对编译器没有这个选项。这并不一定意味着您无法从该编译器中调试代码。例如,我在没有设置调试标志的情况下为Eclipse CDT生成了文件,但是仍然能够调试好。

For reference, here is the list of commands I used for Eclipse CDT (from the project root dir, the cmakelists.txt file is in the src subdirectory):

作为参考,这里是我用于Eclipse CDT的命令列表(从项目根目录,cmakelists)。txt文件在src子目录中):

mkdir eclipse-project
cd eclipse-project
cmake ../src -G "Eclipse CDT - Unix Makefiles"

Then I can open the project from Eclipse and debug. I suspect you'll be able to do the same, whether cmake knows how to enable debug for your compiler or not.

然后,我可以从Eclipse和debug打开这个项目。我猜您也可以这样做,cmake是否知道如何为编译器启用调试。