编辑:我正在使用Microsoft的C / C ++插件进行vscode,您可能会很幸运,可以按照json设置指南进行操作。我还没有尝试过,但是它可能能够帮助您在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).
我能够在命令提示符下重现该错误,并且当我为cygwin PYTHONHOME
和PYTHONPATH
gdb 设置环境变量时,它能够成功运行(例如此答案:https : //stackoverflow.com/a/19377110/2066736)。这就是为什么在我launch.json
这样设置环境变量的原因:
"environment": [ {"name":"PYTHONHOME", "value": "/usr/"}, {"name":"PYTHONPATH", "value": "/usr/lib/python2.7"} ],
但这仍然给我错误。我觉得这是给我这个错误的,因为它只是计划使用环境变量而不是gdb命令运行可执行文件。对使用gdb进行调试有什么帮助吗?