11

I have an existing code base that builds with a makefile and I'd like to use Visual Studio Code to run it.

I started by opening my project directory with Visual Studio Code. Then, for building I created a task as per http://code.visualstudio.com/docs/languages/cpp :

{
    "version": "0.1.0",
    "command": "bash",
    "isShellCommand": true,
    "args":["-c", "cd build && make"]
}

which works fine. I then downloaded the C++ extension and created a launch.json:

{
"version": "0.2.0",
"configurations": [
    {
        "name": "C++ Launch",
        "type": "cppdbg",
        "request": "launch",
        "targetArchitecture": "x64",
        "program": "${workspaceRoot}/build/myProgram",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceRoot}",
        "environment": [],
        "externalConsole": true,
        "linux": {
            "MIMode": "gdb"
        },
        "osx": {
            "MIMode": "lldb"
        },
        "windows": {
            "MIMode": "gdb"
        }
    },
    // attach here, which I don't care about
]
}

This launch file allows me to start my program using the built-in debugger. I know that it works because I see all the symbol files getting loaded and I can pause the program.

However, VS Code doesn't "see" my source files; when I pause it says

 Source /Unknown Source is not available.

I also can't set breakpoints in the source. I see that some symbols get loaded though as I can see my function names on the call stack when I pause execution.

So what did I miss? Do I absolutely have to do as they say here ( http://code.visualstudio.com/docs/languages/cpp ) and make a g++ task where I'll have to manually input all my include paths and linker inputs? The point of using a makefile in the first place was to not have to do this tedious stuff...

Thanks a lot to anyone who knows how to wrangle VS code.

1
  • I think we need to see the makefile to know what the problem actually is. Commented Oct 25, 2023 at 8:17

2 Answers 2

1

You should be able to debug by just using tasks.json and launch.json.

Are you sure you have the -g option set in your makefile?

Another thing - you can have your task be executed on launch by adding "preLaunchTask": "bash" to your your launch.json.

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

1

At windows; Mingw, gdb and -g parameter at compilation of the executable are necessary with c/c++ extension. "preLaunchTask": "bash" is not necessary in launch.json.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.