c-在vs代码中添加-g标志的位置进行调试


我有两个问题。我刚刚安装了VS代码,并设法使其编译C代码并显示输出。但我无法调试。当我添加断点和调试时,红色圆圈将变灰。

我在github上读到,添加一个-g标志会起作用。

Q1。但是在哪里以及如何添加-g标志我还读到:

如何将编译标志-g添加到make文件中?

但它从我的脑海中掠过。

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
}
}
]
}

我试图将tasks.json中的args-o更改为-g,但它也阻止了它的编译,这至少以前是有效的。若我添加了-o,程序仍然并没有调试。

编辑:

Q2.Plus还告诉我是否可以在tasks.json中添加C++路径而不是C

因为我找不到C的路径。互联网上的教程是针对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++"

您应该添加标志,而不是替换"-o"标志。

-o标志告诉编译器输出文件的名称。

因此,取而代之的是例如

"-Wall", "-g", "try.c", "-o", "try"

最新更新