1
votes

I'm trying to lear using CMAKE to create builds. I've been experimenting but can't get debugging to work on my resulting projects. To test this, I've setup a basic hello world project like this: SimpleProject --Include --Main.cpp --CMakeLists.txt

This is the contents of Main.cpp.

#include <iostream>
using namespace std;

int main() {
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    std::getchar();
    return 0;
}

and this is the content of CMakeLists.txt:

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

add_executable(CleanProject Include/Main.cpp)

I now run cmake with the following command, in the developer console: 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

Lastly, I build using 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

If I now try to debug this program, be it in an IDE like eclipse or by using gdb from the command line, I'll get the no debugging symbols found error as seen below.

D:\Development\SimpleProject\Build>C:\MinGW\bin\gdb.exe CleanProject.exe GNU gdb (GDB) 7.6.1 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "mingw32". For bug reporting instructions, please see: http://www.gnu.org/software/gdb/bugs/... Reading symbols from D:\Development\SimpleProject\Build\CleanProject.exe...(no debugging symbols found)...done.

I can't seem to find a fix for this. I've tried adding several different vars to my cmakelist file or as extra options for cmake with no success. Any help would be greatly appreciated as this is the only roadblock left as of now. My bigger projects also build successfully but without debugging it's kinda hard to continue. Thanks!

1
So basically you are asking whether gdb supports .pdb debug information generated by vc++? Related stackoverflow.com/questions/26846516/…user7860670

1 Answers

2
votes

Reading your CMake output:

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

It seems like you are using the Visual Studio compiler.

The way it compiles is incompatible with the GDB debugger, you'll have to use the MSVC debugger instead, which can be run within the visual studio debugger.