Windows 上使用 cmake 的 Visual Studio 代码,如何设置编译器和调试配置

问题描述 投票:0回答:1

我有 Windows 7,有几个不同版本的 Visual Studio 和 MinGW。当我创建一个 cmake 项目并在 Visual Studio Code 中打开它时,它会自动配置为使用 Visual Studio 14 编译器,我还安装了 Visual Studio 17 和 19,版本 17 已安装。

我想知道如何设置运行初始配置时(当构建文件夹为空时)使用哪个编译器以及如何创建调试配置。当我运行不需要配置的普通调试按钮时,断点不会触发。

我尝试过在 launch.json 中使用这些配置文件

"Desktop development with C++" workload.

这些都不起作用,
"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" } ]

配置不起作用,因为代码是用 Visual Studio 编译器编译的,并且我正在尝试使用 MinGW 调试器(这是假设)。

(gdb) Launch
也不起作用,但我不知道为什么,它确实无限期地运行,但没有一个断点起作用。
    

c++ windows visual-studio-code cmake mingw
1个回答
0
投票

删除构建文件夹。
  1. 在 Visual Studio 代码中按 F1 并运行:
  2. (Windows) Launch
  3. f1 并运行:
  4. CMake: scan for kits
  5. 
    
  6. 在第 3 步,系统将要求您选择编译器版本。

© www.soinside.com 2019 - 2024. All rights reserved.