【开发环境】Ubuntu 中使用 VSCode 开发 C/C++ ④ ( 创建 tasks.json 编译器构建配置文件 | tasks.json 编译器构建配置文件分析 )
文章目錄
- 一、創建 tasks.json 編譯器構建配置文件
- 二、tasks.json 編譯器構建配置文件分析
可以參考官方提供的文檔 : https://code.visualstudio.com/docs/cpp/config-linux
使用 VSCode 開發 C/C++ 程序 , 涉及到 333 個配置文件 :
① tasks.json : 編譯器構建 配置文件 ;
② launch.json : 調試器設置 配置文件 ;
③ c_cpp_properties.json : 編譯器路徑和智能代碼提示 配置文件 ;
下面開始逐個 生成 上述配置文件 ;
一、創建 tasks.json 編譯器構建配置文件
tasks.json 編譯器構建配置文件 , 用于告訴 VSCode 如何去編譯這個程序 ;
菜單欄選擇 " 終端 / 配置默認生成任務 " ,
在彈出的對話框中 , 選擇第 222 項 , " C/C++:g++ 生成活動文件 " 選項 ;
點擊該選項 , 即可在 .vscode 目錄中生成 tasks.json 文件 ;
文件內容如下 :
{"version": "2.0.0","tasks": [{"type": "cppbuild","label": "C/C++: g++ 生成活動文件","command": "/usr/bin/g++","args": ["-fdiagnostics-color=always","-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}"],"options": {"cwd": "${fileDirname}"},"problemMatcher": ["$gcc"],"group": {"kind": "build","isDefault": true},"detail": "編譯器: /usr/bin/g++"}] }二、tasks.json 編譯器構建配置文件分析
"label": "C/C++: g++ 生成活動文件", 是編譯 C/C++ 任務名稱 , 該任務名稱可以自定義 ;
"command": "/usr/bin/g++", 中的 command 配置 , 是指定編譯器 , 一般是 gcc 或者 g++ 編譯器 ;
"args" 數組 , 配置的是 command 指定的編譯器后的編譯選項 ;
"args": ["-fdiagnostics-color=always","-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}"],"group" 中的 "isDefault": true 指的是 , 使用 Ctrl + Shift + B 快捷鍵可以運行該任務 , 如果設置為 false , 需要從終端菜單中 , 選擇 " 運行任務 " 來編譯運行程序 ;
"group": {"kind": "build","isDefault": true},總結
以上是生活随笔為你收集整理的【开发环境】Ubuntu 中使用 VSCode 开发 C/C++ ④ ( 创建 tasks.json 编译器构建配置文件 | tasks.json 编译器构建配置文件分析 )的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【开发环境】Ubuntu 中使用 VSC
- 下一篇: 【开发环境】Ubuntu 中使用 VSC