cvisual-studio-codedebugging

How to debug multiple C files in vscode?


i need to debug two differents files "scanner.c" and "memory.c" in vscode. When I click the "build and debug" it shows me an error, i click "debug anyway" and it opens "launch.json" with the following text inside:

    "version": "0.2.0",
"configurations": [
    {
        "name": "gcc - Build and debug active file",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}/${fileBasenameNoExtension}",
        "args": ["scanner.c", "memory.c"],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "lldb",
        "preLaunchTask": "C/C++: gcc build active file",
    }
    
]

}


Solution

  • To debug multiple C/C++ files simultaneously in VsCode you need to build a debuggable executable out of them first (using a build system like make) then start debugging the executable itself. A quick google search brings up a good reference to follow:

    https://dev.to/talhabalaj/setup-visual-studio-code-for-multi-file-c-projects-1jpi