简单的cmake项目,在Windows上使用nmake构建,没有调试符号

问题描述 投票:0回答:1

我正在尝试使用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;
}

这是CMakeLists.txt的内容:

cmake_minimum_required(VERSION 3.15.3)
project(CleanProject LANGUAGES CXX C)

add_executable(CleanProject Include/Main.cpp)

我现在在开发人员控制台中使用以下命令运行cmake:D:\ Development \ SimpleProject \ Build> cmake -DCMAKE_BUILD_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.exeGNU gdb(GDB)7.6.1版权所有(C)2013自由软件基金会,Inc.许可证GPLv3 +:GNU GPL版本3或更高版本http://gnu.org/licenses/gpl.html这是免费软件:您可以自由更改和重新分发它。在法律允许的范围内,没有任何担保。输入“显示复制”和“显示保修”了解详情。该GDB被配置为“ mingw32”。有关错误报告的说明,请参阅:http://www.gnu.org/software/gdb/bugs/...从D:\ Development \ SimpleProject \ Build \ CleanProject.exe中读取符号...(未找到调试符号)...完成。

我似乎找不到解决方法。我尝试将多个不同的变量添加到我的cmakelist文件中,或者作为cmake的其他选项没有成功。任何帮助将不胜感激,因为这是到目前为止唯一剩下的障碍。我的较大项目也可以成功构建,但是如果不调试,将很难继续。谢谢!

c++ cmake gdb debug-symbols nmake
1个回答
0
投票

读取您的CMake输出:

-- 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

似乎您正在使用Visual Studio编译器。

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

© www.soinside.com 2019 - 2024. All rights reserved.