编辑:我正在使用Microsoft's C/C++ plugin用于vscode,您可以通过关注this guide for the json setup来获得它的工作。我还没有尝试过,但它可能能帮助你在Windows上运行它。如果我弄清楚并有时间,我会尝试发一个答案,但除此之外随时回答,如果你的工作,我会接受并赞成它。也可以尝试将此"key": "value"
对"miDebuggerPath": "C:\\rhcygwin64\\bin\\gdb.exe"
的值更改为窗口的Cygwin输出which gdb
的路径。
我一直在努力让Windows上的Visual Studio代码中的C ++构建和调试工作。也许我会以错误的方式解决这个问题。我已经通过cygwin下载了g ++并将其添加到我的路径中。我的tasks.json
文件看起来像这样。
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
"args": ["-g", "main.cpp"],
"showOutput": "always"
}
我运行此任务,它似乎构建可执行文件没有问题。问题是在下一步中启动调试器。我的launch.json
看起来像这样:
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [
{"name":"PYTHONHOME", "value": "/usr/"},
{"name":"PYTHONPATH", "value": "/usr/lib/python2.7"}
],
"externalConsole": true,
"miDebuggerPath": "C:\\rhcygwin64\\bin\\gdb.exe",
"linux": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
},
{
"name": "C++ Attach",
"type": "cppdbg",
"request": "attach",
"program": "enter program name, for example ${workspaceRoot}/a.out",
"processId": "${command.pickProcess}",
"linux": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
}
]
}
然后,当我启动调试器时出现以下错误:
Starting: "C:\rhcygwin64\bin\gdb.exe" --interpreter=mi
ImportError: No module named site
"C:\rhcygwin64\bin\gdb.exe" exited with code 1 (0x1).
我能够在命令提示符中重现错误,当我为PYTHONHOME
和PYTHONPATH
设置环境变量时,cygwin gdb能够成功运行(如此答案:{{3 }})。所以这就是为什么在我launch.json
我设置环境变量的原因如下:
"environment": [
{"name":"PYTHONHOME", "value": "/usr/"},
{"name":"PYTHONPATH", "value": "/usr/lib/python2.7"}
],
但它仍然给我错误。我觉得它给了我这个错误,因为它只计划使用环境变量而不是gdb命令运行可执行文件。有关使用gdb进行调试的任何帮助吗?