我有两个问题。我刚刚安装了VS代码,并设法使其编译C代码并显示输出。但是我无法调试。当我添加断点和调试时,红色圆圈变灰。
I read on github that adding a -g flag will work。
问题1。但是在何处以及如何添加-g
标志?我也读到:
How to add compile flag -g to a make file?
但是它超过了我的头。
launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/try.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gdb.exe",
"preLaunchTask": "echo",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\lib\\gcc\\i686-w64-mingw32\\8.1.0\\include\\c++"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "gcc",
"args": [
"-Wall", "try.c", "-o", "try"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
我试图将args
中的tasks.json
从-o
更改为-g
,但是这也阻止了它的编译,至少以前是这样的。如果我除了-o
以外添加,程序仍然没有调试。
编辑:
第二季度。另外还要告诉我是否可以在tasks.json
中添加C ++的路径而不是C?
因为我找不到C的路径。Internet上的教程适用于C ++,他们告诉他们在那里设置C ++路径。但是我想编译C代码,尽管它们现在正在编译。
"includePath": [
"${workspaceFolder}/**",
"C:\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\lib\\gcc\\i686-w64-mingw32\\8.1.0\\include\\c++"
答案 0 :(得分:0)
您应该添加标志,而不是替换"-o"
标志。
-o
标志告诉编译器输出文件的名称。
因此,例如
"-Wall", "-g", "try.c", "-o", "try"