Windows 上使用 cmake 的 Visual Studio 代码,如何设置编译器和调试配置
我有 Windows 7,带有几个不同版本的 Visual Studio 和 MinGW。当我创建一个 cmake 项目并在 Visual Studio Code 中打开它时,它会自动配置为使用 Visual Studio 14 编译器,我还安装了 Visual Studio 17 和 19,版本 17 具有“使用 C++ 进行桌面开发”工作负载。代码>已安装。
我想知道如何设置运行初始配置时(当构建文件夹为空时)使用哪个编译器以及如何创建调试配置。当我运行不需要配置的普通调试按钮时,断点不会触发。
我尝试过在 launch.json 中使用这些配置文件
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"env": {
"Path": "${env:Path};D:\\Installation\\oracClient 19\\instantclient_19_14\\"
},
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "c:\\Users\\marko.grujic.CHIP\\.vscode\\extensions\\ms-vscode.cpptools-1.8.4\\debugAdapters\\bin\\WindowsDebugLauncher.exe",
"logging": {
"engineLogging": true
},
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
},
{
"name": "(Windows) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"env": {
"Path": "${env:Path};D:\\Installation\\oracClient 19\\instantclient_19_14\\"
},
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
"logging": {
"engineLogging": true
},
"console": "externalTerminal"
}
]
,但这些都不起作用,(gdb) Launch
配置不起作用,因为代码是用 Visual Studio 编译器编译的,并且我正在尝试使用 MinGW 调试器(这是假设)。 (Windows) Launch
也不起作用,但我不知道为什么,它确实无限期地运行,但没有一个断点起作用。
I have Windows 7 with few different versions of Visual Studio and MinGW. When I create a cmake project and open it in Visual Studio Code it get configured automatically to use Visual Studio 14 compiler, I also have Visual Studio 17 and 19 installed, version 17 have "Desktop development with C++" workload.
installed.
I would like to know how to set which compiler to use when running initial configuration (when build folder is empty) and how to create a debug configuration. When I run plain debug button that do not require the configuration the break point do not trigger.
I have tried with these config files in launch.json
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"env": {
"Path": "${env:Path};D:\\Installation\\oracClient 19\\instantclient_19_14\\"
},
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "c:\\Users\\marko.grujic.CHIP\\.vscode\\extensions\\ms-vscode.cpptools-1.8.4\\debugAdapters\\bin\\WindowsDebugLauncher.exe",
"logging": {
"engineLogging": true
},
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
},
{
"name": "(Windows) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"env": {
"Path": "${env:Path};D:\\Installation\\oracClient 19\\instantclient_19_14\\"
},
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
"logging": {
"engineLogging": true
},
"console": "externalTerminal"
}
]
Non of these work, (gdb) Launch
config do not work because the code was compiled with Visual Studio compiler and I am trying to use MinGW debugger (This is assumption).(Windows) Launch
also do not work but I have no idea why, it does run indefinitely but none of breakpoints work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要更改编译器,我建议:
CMake:扫描套件
。CMake:选择一个套件
。在第 3 步中,系统会要求您选择编译器版本。
To change a compiler I recommend:
CMake: scan for kits
.CMake: select a kit
.On step number 3 you will be asked to select a compiler version.