栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

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

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

文章目录
  • 遇到的3个问题
          • 1. “终端将被任务重用,按任意键关闭”
          • 2. “unable to start debugging...is mising or valid”
          • 3. 黑窗口一闪而过的问题
  • 3个json文件内容

首先根据网上的教程下载了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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/849523.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号