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

发布于 2025-01-14 01:00:15 字数 2427 浏览 4 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉宸 2025-01-21 01:00:15

要更改编译器,我建议:

  1. 删除构建文件夹。
  2. 在 Visual Studio Code 中按 F1 并运行:CMake:扫描套件
  3. f1 并运行:CMake:选择一个套件

在第 3 步中,系统会要求您选择编译器版本。

To change a compiler I recommend:

  1. deleting the build folder.
  2. From visual studio code press f1 and run: CMake: scan for kits.
  3. f1 and run: CMake: select a kit.

On step number 3 you will be asked to select a compiler version.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文