C++ 简单的cmake项目,在windows上使用nmake生成没有调试符号

C++ 简单的cmake项目,在windows上使用nmake生成没有调试符号,c++,cmake,gdb,debug-symbols,nmake,C++,Cmake,Gdb,Debug Symbols,Nmake,我正在尝试学习使用CMAKE创建构建。我一直在试验,但无法在我的结果项目上进行调试。为了测试这一点,我设置了一个基本的hello world项目,如下所示: 简单工程 --包括 --Main.cpp --CMakeLists.txt 这是Main.cpp的内容 #include <iostream> using namespace std; int main() { cout << "!!!Hello World!!!" << endl; // pr

我正在尝试学习使用CMAKE创建构建。我一直在试验,但无法在我的结果项目上进行调试。为了测试这一点,我设置了一个基本的hello world项目,如下所示: 简单工程 --包括 --Main.cpp --CMakeLists.txt

这是Main.cpp的内容

#include <iostream>
using namespace std;

int main() {
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    std::getchar();
    return 0;
}
现在,我在开发人员控制台中使用以下命令运行cmake: D:\Development\SimpleProject\Build>cmake-DCMAKE\u Build\u TYPE=Debug

-- Building for: NMake Makefiles
-- The CXX compiler identification is MSVC 19.23.28105.4
-- The C compiler identification is MSVC 19.23.28105.4
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual 
Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx86/x86/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual 
Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx86/x86/cl.exe -- 
works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual 
Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual 
Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx86/x86/cl.exe -- 
works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Development/SimpleProject/Build
最后,我使用nmake构建

Microsoft (R) Program Maintenance Utility Version 14.23.28105.4
Copyright (C) Microsoft Corporation.  All rights reserved.

Scanning dependencies of target CleanProject
[ 50%] Building CXX object CMakeFiles/CleanProject.dir/Include/Main.cpp.obj
Main.cpp
[100%] Linking CXX executable CleanProject.exe
[100%] Built target CleanProject
如果我现在尝试调试这个程序,无论是在像eclipse这样的IDE中还是通过从命令行使用gdb,我都会得到如下所示的“未找到调试符号”错误

D:\Development\SimpleProject\Build>C:\MinGW\bin\gdb.exe CleanProject.exe GNU gdb(gdb)7.6.1 版权所有(C)2013免费软件基金会。 许可证GPLv3+:GNU GPL版本3或更高版本 这是自由软件:您可以自由更改和重新发布它。 在法律允许的范围内,不存在任何担保。键入“显示复制” 和“显示保修”了解详细信息。 此GDB配置为“mingw32”。 有关错误报告说明,请参阅: ... 正在从D:\Development\SimpleProject\Build\CleanProject.exe读取符号…(未找到调试符号)…完成

我似乎找不到解决办法。我尝试将几个不同的变量添加到我的cmakelist文件或作为cmake的额外选项,但没有成功。 任何帮助都将不胜感激,因为这是目前为止仅存的障碍。我更大的项目也能成功构建,但如果不进行调试,就很难继续。
谢谢

读取您的CMake输出:

看起来您正在使用Visual Studio编译器


它的编译方式与GDB调试器不兼容,您必须改用MSVC调试器,它可以在visual studio调试器中运行。

因此,基本上您是在询问GDB是否支持vc++生成的.pdb调试信息?非常感谢!我不知道gdb不能处理这件事。我现在已经切换到MinGW来构建我的项目,现在我可以用gdb来调试。
Microsoft (R) Program Maintenance Utility Version 14.23.28105.4
Copyright (C) Microsoft Corporation.  All rights reserved.

Scanning dependencies of target CleanProject
[ 50%] Building CXX object CMakeFiles/CleanProject.dir/Include/Main.cpp.obj
Main.cpp
[100%] Linking CXX executable CleanProject.exe
[100%] Built target CleanProject
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx86/x86/cl.exe -- works