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