Fastor·Breaker 2024-08-21 13:48 采纳率: 0%
浏览 4

配置vs code 时的问题C++

终端显示

Executing task: C/C++: g++.exe build active file 

Starting build...
cmd /c chcp 65001>nul && C:\msys64\ucrt64\bin\g++.exe -fdiagnostics-color=always -g C:\Users\hy\Desktop\C\main.cpp -o C:\Users\hy\Desktop\C\main.exe
'cmd' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���

Build finished with error(s).

 *  The terminal process failed to launch (exit code: -1). 
 *  Terminal will be reused by tasks, press any key to close it. 

tasks.json是

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\msys64\\ucrt64\\bin\\g++.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"
}

恳请高人指点,谢谢

  • 写回答

1条回答 默认 最新

  • zhenghaoming0707 2024-08-21 14:25
    关注

    从错误信息来看,问题可能出在命令行编码设置上。错误信息中提到“'cmd' �����ڲ����ⲿ���Ҳ���ǿ����еij��� ���������ļ���”,这可能是由于编码问题导致的乱码。

    你可以尝试以下步骤来解决这个问题:

    1. 修改 tasks.json 文件
      tasks.json 文件中添加一个环境变量设置,确保命令行使用 UTF-8 编码。

      {
          "tasks": [
              {
                  "type": "cppbuild",
                  "label": "C/C++: g++.exe build active file",
                  "command": "C:\\msys64\\ucrt64\\bin\\g++.exe",
                  "args": [
                      "-fdiagnostics-color=always",
                      "-g",
                      "${file}",
                      "-o",
                      "${fileDirname}\\${fileBasenameNoExtension}.exe"
                  ],
                  "options": {
                      "cwd": "${fileDirname}",
                      "env": {
                          "CHCP": "65001"
                      }
                  },
                  "problemMatcher": [
                      "$gcc"
                  ],
                  "group": {
                      "kind": "build",
                      "isDefault": true
                  },
                  "detail": "Task generated by Debugger."
              }
          ],
          "version": "2.0.0"
      }
      
    2. 修改 VS Code 设置
      在 VS Code 的设置中,确保终端使用 UTF-8 编码。

      打开 VS Code 设置(快捷键 Ctrl + ,),搜索 terminal.integrated.shellArgs.windows,添加以下配置:

      "terminal.integrated.shellArgs.windows": [
          "/K",
          "chcp 65001"
      ]
      
    3. 检查 g++ 路径
      确保 C:\\msys64\\ucrt64\\bin\\g++.exe 路径是正确的,并且该路径在你的系统环境变量中。

    4. 重新启动 VS Code
      完成上述修改后,重新启动 VS Code,然后再次尝试编译。

    通过这些步骤,你应该能够解决编码问题导致的终端错误。如果问题依然存在,请检查其他可能的配置问题或提供更多的错误信息以便进一步诊断。

    评论

报告相同问题?

问题事件

  • 创建了问题 8月21日

悬赏问题

  • ¥15 模电中二极管,三极管和电容的应用
  • ¥15 关于模型导入UNITY的.FBX: Check external application preferences.警告。
  • ¥15 气象网格数据与卫星轨道数据如何匹配
  • ¥100 java ee ssm项目 悬赏,感兴趣直接联系我
  • ¥15 微软账户问题不小心注销了好像
  • ¥15 x264库中预测模式字IPM、运动向量差MVD、量化后的DCT系数的位置
  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥20 关于web前端如何播放二次加密m3u8视频的问题
  • ¥15 使用百度地图api 位置函数报错?
  • ¥15 metamask如何添加TRON自定义网络