Can't run C++ Debugger in VSCode

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.


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.



    "configurations": [
            "name": "Linux",
            "includePath": [
            "defines": [],
            "compilerPath": "/nix/store/75slks1wr3b3sxr5advswjzg9lvbv9jc-gcc-wrapper-12.3.0/bin/gcc",
            "compilerArgs": [],
            "cStandard": "c17",
            "cppStandard": "gnu++17",
            "intelliSenseMode": "linux-gcc-x64"
    "version": 4


    "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": [
            "group": "build",
            "detail": "Task generated by Debugger."


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

Did you have any luck with this? Seem to have the same problem and have not been able to found out where it is failing.

I don’t know what was broken but my solution was to change the vscode package I was using.

Insead of usign vscode use vscode.fhs, you can learn more about it in the nixos wiki.

With this package you can:

  • install extension from the vscode gui as in any other operating system
  • access all the programs and libraries you need with the conventional filesystem structure of any other distro.

The last step of the wiki guide is very important, you have to specify all the packages your vscode will need or they will not be accessible from the conventional paths.

Other then vscode extensions is great also to run binaries that rely on shared libraries.


  • I don’t know if you can specify the extension you want in your configuration if you use vscode.fhs. Anyway I have all my extensions synched so I don’t care.

  • You can’t run commands as root from vscode terminal, it’s annoying but just open another terminal app and you are fine.


Honestly I don’t know why this is not the first option presented in the wiki. Has some limitations but the other options are horribly broken.

That worked thanks. I completely ignored that section when I read through the wiki so would not have gotten there at all!