运行C++使用clang++在VSCODE终端中(Midebuggerpath的值无效)

发布于 2025-02-05 07:06:08 字数 3966 浏览 4 评论 0原文

我是新手使用C ++的新手,并且一直在尝试弄清楚这几个小时。我正在使用Windows。我安装了VSCODE,C ++的扩展名,安装了MSYS2,并设置了Clang ++。现在,我正在尝试使用其终端在VSCODE中运行file.cpp。只是你好的世界。使用以下任务时,它执行但然后投掷“无法开始调试。Midebuggerpath的值无效”。 Hello World不会输出,我很茫然。 有人知道为什么会发生这种情况,并就如何修复有建议吗?谢谢您,非常感谢!

这是我试图在终端

执行任务中运行的命令的图片: C/C ++:Clang ++。EXE构建活动文件<

开始构建... c:\ msys64 \ mingw64 \ bin \ clang ++。exe -fdiagnostics -color =始终-g c:\ users \ users \ daniel \ daniel \ desktop \ desktop \ test \ hello.cpp -o c:\ users \ users \ daniel \ daniel \ daniel \ daniel

成功建造完成。

我的代码

#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;}

我的启动.json

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []}

我的任务。

{
"tasks": [
    {
        "type": "cppbuild",
        "label": "C/C++: clang++.exe build active file",
        "command": "C:\\msys64\\mingw64\\bin\\clang++.exe",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build",
        "detail": "Task generated by Debugger."
    },
    {
        "type": "cppbuild",
        "label": "C/C++: g++.exe build active file",
        "command": "C:\\msys64\\mingw64\\bin\\g++.exe",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build",
        "detail": "Task generated by Debugger."
    },
    {
        "type": "cppbuild",
        "label": "C/C++: clang-cl.exe build active file",
        "command": "C:\\msys64\\mingw64\\bin\\clang-cl.exe",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build",
        "detail": "Task generated by Debugger."
    },
    {
        "type": "cppbuild",
        "label": "C/C++: clang-cpp.exe build active file",
        "command": "C:\\msys64\\mingw64\\bin\\clang-cpp.exe",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build",
        "detail": "Task generated by Debugger."
    },
    {
        "type": "cppbuild",
        "label": "C/C++: gcc.exe build active file",
        "command": "C:\\msys64\\mingw64\\bin\\gcc.exe",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "Task generated by Debugger."
    }
],
"version": "2.0.0"}

I'm new to using C++ and have been trying to figure this out for hours. I'm using windows. I installed VScode, the extension for C++, installed MSYS2, and set up clang++. Now I'm trying to run file hello.cpp in VScode using their terminal. It's just hello world. When using the below task, it executes but then throws "Unable to start debugging. The value of miDebuggerPath is invalid." The hello world does not output and I'm at a loss. Does anyone know why this is happening and have suggestions on how to fix? Thank you and much appreciated!

Here is a pic of the commands I've been trying to run in the terminal

Executing task: C/C++: clang++.exe build active file <

Starting build...
C:\msys64\mingw64\bin\clang++.exe -fdiagnostics-color=always -g C:\Users\Daniel\Desktop\test\hello.cpp -o C:\Users\Daniel\Desktop\test\hello.exe

Build finished successfully.

My code

#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;}

My launch.json

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []}

My tasks.json

{
"tasks": [
    {
        "type": "cppbuild",
        "label": "C/C++: clang++.exe build active file",
        "command": "C:\\msys64\\mingw64\\bin\\clang++.exe",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build",
        "detail": "Task generated by Debugger."
    },
    {
        "type": "cppbuild",
        "label": "C/C++: g++.exe build active file",
        "command": "C:\\msys64\\mingw64\\bin\\g++.exe",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build",
        "detail": "Task generated by Debugger."
    },
    {
        "type": "cppbuild",
        "label": "C/C++: clang-cl.exe build active file",
        "command": "C:\\msys64\\mingw64\\bin\\clang-cl.exe",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build",
        "detail": "Task generated by Debugger."
    },
    {
        "type": "cppbuild",
        "label": "C/C++: clang-cpp.exe build active file",
        "command": "C:\\msys64\\mingw64\\bin\\clang-cpp.exe",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build",
        "detail": "Task generated by Debugger."
    },
    {
        "type": "cppbuild",
        "label": "C/C++: gcc.exe build active file",
        "command": "C:\\msys64\\mingw64\\bin\\gcc.exe",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "Task generated by Debugger."
    }
],
"version": "2.0.0"}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文