I spent one day in the attempt of running a hello world cpp file with no success.
What is working
I have a task that builds main.cpp
and produces a main
file in the same folder which runs correctly when executed from the shell with ./main
, I also tried to debug it directly with gdb which works correctly. The completion and highlighting also works after setting the proper paths.
What is not working
The problem is the Debugger, it works for other languages (python) but when I run it with this configuration it does nothing. The preLaunch task runs, creates main
and then nothing. The debugger is not starting at all, no output in debug console, no output in terminal, all I see is a loading bar on the debugger for just a second. I activated all possible debugger logs but this was useless, it’s printing the configuration in my launch.json each time I run the debugger but is not printing anything useful.
Setup:
I installed vscode
, gdb
and gcc
system-wide in my configuration.nix
, I installed the extensions manually from vscode (C/C++ Extensions pack).
My main.cpp
file is in the root of the project and the main
binary is created in the same folder, no other files are involved to build it.
Settings
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/nix/store/75slks1wr3b3sxr5advswjzg9lvbv9jc-gcc-wrapper-12.3.0/bin/gcc",
"compilerArgs": [],
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/run/current-system/sw/bin/g++ -g ${file} -o ${fileDirname}/${fileBasenameNoExtension}",
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
}
],
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "g++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"logging": {
"moduleLoad": true,
"trace": true,
"engineLogging": true,
"exceptions": true,
"programOutput": true,
"traceResponse": true,
},
"preLaunchTask": "g++ build active file",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"miDebuggerPath": "/nix/store/3xy76jkizzl5xvarhzdmm11r8flv5vqk-gdb-13.2/bin/gdb"
}
]
}
do you have any idea how to solve this?