在deepin 15.5中安裝vs code並配置c/c++環境(二)——配置clang
阿新 • • 發佈:2019-01-07
接上文:https://blog.csdn.net/defetc/article/details/79946100
本文配置檔案參考:https://www.zhihu.com/question/30315894/answer/154979413
一、安裝clang
apt-get install clang
二、安裝vs code相關外掛
C/C++ Clang Command Adapter
三、修改配置檔案
tasks.json:
{ "version": "2.0.0", "tasks": [ { "label": "build", // 任務名稱,與launch.json的preLaunchTask相對應 "command": "clang++", // 要使用的編譯器 "args": [ "${file}", "-o", // 指定輸出檔名,不加該引數則預設輸出a.exe "${fileDirname}/${fileBasenameNoExtension}.out", "-g", // 生成和除錯有關的資訊 "-Wall", // 開啟額外警告 "-static-libgcc", // 靜態連結 "-fcolor-diagnostics", //"--target=x86_64-w64-mingw", // 預設target為msvc,不加這一條就會找不到標頭檔案 "-std=c++14" // C語言最新標準為c11,或根據自己的需要進行修改 ], // 編譯命令引數 "type": "shell", "group": { "kind": "build", "isDefault": true // 設為false可做到一個tasks.json配置多個編譯指令,需要自己修改本檔案,我這裡不多提 }, "presentation": { "echo": true, "reveal": "always", // 在“終端”中顯示編譯資訊的策略,可以為always,silent,never。具體參見VSC的文件 "focus": false, // 設為true後可以使執行task時焦點聚集在終端,但對編譯c和c++來說,設為true沒有意義 "panel": "shared" // 不同的檔案的編譯資訊共享一個終端面板 } // "problemMatcher":"$gcc" // 如果你不使用clang,去掉前面的註釋符,並在上一條之後加個逗號。照著我的教程做的不需要改(也可以把這行刪去) } ] }
"-std=c++14"這裡根據自己情況修改,後面的settings.json也一樣。
settings.json:
{ "files.associations": { "iostream": "cpp", "ostream": "cpp" }, //"files.defaultLanguage": "cpp", // ctrl+N新建檔案後預設的語言 "code-runner.runInTerminal": true, // 設定成false會在“輸出”中輸出,無法互動 "code-runner.executorMap": { //"c": "cd $dir && clang $fileName -o $fileNameWithoutExt.out -g -Wall -static-libgcc -fcolor-diagnostics -std=c11 && $dir$fileNameWithoutExt", //"cpp": "cd $dir && clang++ $fileName -o $fileNameWithoutExt.out -g -Wall -static-libgcc -fcolor-diagnostics -std=c++14 && $dir$fileNameWithoutExt" }, // 設定code runner的命令列 "code-runner.saveFileBeforeRun": true, // run code前儲存 "code-runner.preserveFocus": true, // 若為false,run code後游標會聚焦到終端上。如果需要頻繁輸入資料可設為false "code-runner.clearPreviousOutput": false, // 每次run code前清空屬於code runner的終端訊息 "C_Cpp.clang_format_sortIncludes": true, // 格式化時調整include的順序(按字母排序) "C_Cpp.intelliSenseEngine": "Default", // 可以為Default或Tag Parser,後者較老,功能較簡單。具體差別參考cpptools外掛文件 "C_Cpp.errorSquiggles": "Disabled", // 因為有clang的lint,所以關掉 "editor.formatOnType": true, // 輸入時就進行格式化,預設觸發字元較少,分號可以觸發 "editor.snippetSuggestions": "top", // snippets程式碼優先顯示補全 "clang.cflags": [ // 控制c語言靜態檢測的引數 //"--target=x86_64-w64-mingw", "-std=c11", "-Wall" ], "clang.cxxflags": [ // 控制c++靜態檢測時的引數 //"--target=x86_64-w64-mingw", "-std=c++14", "-Wall" ], //"clang.completion.enable":false // 效果稍好,但太卡,故關掉 }
這裡面還有另外幾個外掛的配置:“code runner”、“C/C++ Snippets”。其中“code runner"的”code-runner.executorMap“配置被我註釋掉了。那裡本來意在使code runner也呼叫clang,可惜實際使用中會報錯。我不知道該怎麼修改,若有朋友知道該如何修改,請在評論區指出!