• vscode支持c++编译


    1、summary

       之前已经写过vscode配置c++环境的方式,在使用过程中,发现现在的编译方式没有支持c++11的新特性,通过配置支持c++11
    
    • 1

    2、支持c++11的方式

    • 确认g++版本
      仅g++ 4.8及以上版本才支持C++ 11标准,需要确认g++版本
      g++ --version
      
      • 1
    • 编译c++11的方法
      g++ -std=c++11 test_c11.cpp
      
      • 1

    3、在vscode编译时支持c++11

    在配置c++编译环境时,有3个配置文件,launch.json文件对应的name即选择编译时对应的编译配置。
    
    • 1
    1. 找到当前选择的配置,找到对应的item

          "configurations": [  
          {  
              "name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示  
              "type": "cppdbg",       // 配置类型,这里只能为cppdbg  
              "request": "launch",    // 请求配置类型,可以为launch(启动)或attach(附加)  
              "program": "${workspaceFolder}/exe/${fileBasenameNoExtension}.exe",// 将要进行调试的程序的路径  
              "args": [],             // 程序调试时传递给程序的命令行参数,一般设为空即可  
              "stopAtEntry": false,   // 设为true时程序将暂停在程序入口处,一般设置为false  
              "cwd": "${workspaceFolder}", // 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录  
              "environment": [],  
              "externalConsole": false, // true则弹出终端,false会在下方terminal直接输出
              "MIMode": "gdb",   
              // 这里的路径需要修改。改成自己的路径
              "miDebuggerPath": "xxxxxxx/gdb.exe",
      
              "preLaunchTask": "g++", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc  
              "setupCommands": [  
                  {   
      	    "description": "Enable pretty-printing for gdb",  
                      "text": "-enable-pretty-printing",  
                      "ignoreFailures": true  
                  }  
              ]  
          }  
      ] 
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18
      • 19
      • 20
      • 21
      • 22
      • 23
      • 24
      • 25
    2. 在tasks.json文件下找到preLaunchTask项

      "version": "2.0.0",
      "command": "g++",
      "args": [
          "-g",
          "${file}",
          "-o",
          "${workspaceFolder}/exe/${fileBasenameNoExtension}.exe"
      ],
      "problemMatcher": {
      ....
      },
      "tasks": [....
      ]
      
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
    3. 添加配置
      在args中添加 -std=c++11配置,尝试了一下,需要填在生成的文件之后

      "version": "2.0.0",
      "command": "g++",
      "args": [
          "-g",
          "${file}",
          "-o",
          "${workspaceFolder}/exe/${fileBasenameNoExtension}.exe",
          "-std=c++11"
      ],
      "problemMatcher": {
      ....
      },
      "tasks": [....
      ] 
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14

    https://blog.csdn.net/qq_21397217/article/details/51171964

  • 相关阅读:
    一文看懂MES系统能实现企业哪些目标
    C专家编程 第3章 分析C语言的声明 3.5 typedef可以成为你的朋友
    Java内存溢出(OOM)分析
    安卓毕业设计app项目基于Uniapp+SSM实现的安卓的掌上校园系统食堂缴费图书馆预约
    如何实现模拟量信号远距离无线传输?
    职场中,如何更高效地分析和解决问题(一)
    【数学建模】微分方程数值解,求海上缉私问题
    求一份网页设计结课大作业,要求用到html,css,javascript,的知识
    SELinux
    HDL-Bits 刷题记录 03
  • 原文地址:https://blog.csdn.net/qq_41940001/article/details/127848385