VScode配置C++环境遇到的一些问题


首先根据网上的教程下载了mingw64,并新建了.vscode环境。
文末贴上了这三个json文件的内容。

接下来讲讲我在配置的过程中遇到的一些问题。

第一次配置是在去年准备打蓝桥杯的时候,由于我本身学的是前端,对vscode感到十分亲切,但是后面配置不大理想,记得当时是只能在powershell上丑陋地显示一下结果,并且运行得等个一两秒,极度不舒适,后面开始转战devc++。

后面图形引擎课程作业需要配置opengl环境。不得不再次配c++环境~遇到了如下几个简单的小问题:

遇到的3个问题

1. “终端将被任务重用,按任意键关闭”

原解答
原因是本地窗口是共享的,需要结束一个才能执行另一个,有两种解决方法:1.为每个进程创建一个新端口;2.把端口聚焦到当前进程

//选其中一个即可
"presentation": { 
     "focus": true //默认为“false“
     "panel": "new" //默认为“shared“表示共享,改成new之后每个进程创建新的端口
}

后面测试的halloworld成功执行,是熟悉的黑窗口,开心~
在这里插入图片描述

2. “unable to start debugging…is mising or valid”

在这里插入图片描述
这个问题我也找了网上一些博客,并且关注到了C文件要在.vscode的同级目录下或者更低级目录的条件,但后面我的解决办法是不使用英文命名,改成全英文就解决啦

3. 黑窗口一闪而过的问题

查了博客说是要在return语句前加上 getchar();
加了这个语句后确实解决了问题,但是后面,其他文件不加这条语句也依然可以运行。

3个json文件内容

//c_cpp_properties.json
{
  "configurations": [
      {
          "name": "Win32",
          "includePath": [
              "${workspaceFolder}/**"
          ],
          "defines": [
              "_DEBUG",
              "UNICODE",
              "_UNICODE"
          ],
          "compilerPath": "D:/vscode/x86_64-8.1.0-release-win32-seh-rt_v6-rev0/mingw64/bin/g++.exe",
          "cStandard": "c11",
          "cppStandard": "c++17",
          "intelliSenseMode": "gcc-x64"
      }
  ],
  "version": 4
}

//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": [

        {
            "name": "(gdb) Launch",
            "preLaunchTask": "g++.exe build active file",//调试前执行的任务,就是之前配置的tasks.json中的label字段
            "type": "cppdbg",//配置类型,只能为cppdbg
            "request": "launch",//请求配置类型,可以为launch(启动)或attach(附加)
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",//调试程序的路径名称
            "args": [],//调试传递参数
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,//true显示外置的控制台窗口,false显示内置终端
            "MIMode": "gdb",
            "miDebuggerPath": "D:/vscode/x86_64-8.1.0-release-win32-seh-rt_v6-rev0/mingw64/bin/gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

tasks.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": [

        {
            "name": "(gdb) Launch",
            "preLaunchTask": "g++.exe build active file",//调试前执行的任务,就是之前配置的tasks.json中的label字段
            "type": "cppdbg",//配置类型,只能为cppdbg
            "request": "launch",//请求配置类型,可以为launch(启动)或attach(附加)
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",//调试程序的路径名称
            "args": [],//调试传递参数
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,//true显示外置的控制台窗口,false显示内置终端
            "MIMode": "gdb",
            "miDebuggerPath": "D:/vscode/x86_64-8.1.0-release-win32-seh-rt_v6-rev0/mingw64/bin/gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

注意修改对应的mingw64

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值