Maxis
Maxis

Reputation: 3

vs code to run c code

I have an existing code base that builds with a makefile and I'd like to use Visual Studio Code to run it. There are my launch.json and tasks.json.

{
"version": "0.2.0",
"configurations": [{
    "name": "C Launch (GDB)", 
    "type": "cppdbg", 
    "request": "launch",
    "launchOptionType": "Local", 
    "targetArchitecture": "x64",         
    "cwd": "${workspaceRoot}", 
    "program": "E:/code/c", 
    "miDebuggerPath": "E:/Program Files/TDM-GCC-64/bin/gdb64.exe", 
    "args": [""],
    "stopAtEntry": false, 
    "externalConsole": true, 
    "preLaunchTask": "gcc"   
}]
}   


{
"version": "0.1.0",
"command": "gcc", 
"args": ["${file}", "-o", "${fileBasenameNoExtension}.exe", "-g3", "-Og", "-Wall", "-static-libgcc", "-std=c11", "-fexec-charset=GBK", "-finput-charset=UTF-8"],  
"showOutput": "always",
"problemMatcher": {
    "owner": "c",
    "fileLocation": ["relative", "${workspaceRoot}"],
    "pattern": {
        "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
        "file": 1,
        "line": 2,
        "column": 3,
        "severity": 4,
        "message": 5
    } 
}
}

then when I run Hello world,then will have some problems.

enter image description here

Upvotes: 0

Views: 355

Answers (1)

Matt Bierner
Matt Bierner

Reputation: 65593

Try changing your paths to use \ instead of / on Windows. Since you have to escape \ in json strings, the actual value would be:

"program": "E:\\code\\c\\${fileBasenameNoExtension}.exe"

provided the built executable is actually at E:\code\c

Upvotes: 1

Related Questions