在deepin 15.5中安裝vs code並配置c/c++環境
阿新 • • 發佈:2018-12-27
參考了以下幾篇文章:
https://www.zhihu.com/question/30315894/answer/154979413(雖然講解的是Windows環境中的安裝,但十分詳盡,很有參考價值);
https://my.oschina.net/u/1044667/blog/832111;
https://blog.csdn.net/u011258217/article/details/78693564
一、vs code安裝
直接在deepin商店下載即可。
二、安裝gcc/g++
命令列: sudo apt-get install build-essential
三、外掛安裝
- C/C++(製作者是microsoft,最基礎的外掛)
- Code Runner(實用工具,可以選中程式碼塊後,右鍵選擇“run coder”直接執行程式碼,右上角也有快捷按鈕)
下面的外掛都是知乎那篇文章推薦的:
- C/C++ Clang Command Adapter:提供靜態檢測(Lint)
- Include Autocomplete:提供標頭檔案補全
- C/C++ Snippets:Snippets即重用程式碼塊
其他可選外掛:
- Bracket Pair Colorizer:彩虹花括號
- One Dark Pro:大概是VS Code安裝量最高的主題
- GBKtoUTF8:把GBK編碼的文件轉換成UTF8編碼的
四、配置檔案
- 修改其中的program欄位值,改為編譯生成的可執行檔案路徑。如
"program": "${workspaceRoot}/${fileBasenameNoExtension}.out"
。即,若原始檔是case.c,則將除錯case.out檔案。 - 給launch.json新增一個任務選項:
"preLaunchTask": "build"
,"preLaunchTask
{
// 使用 IntelliSense 瞭解相關屬性。
// 懸停以檢視現有屬性的描述。
// 欲瞭解更多資訊,請訪問: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build"
}
]
}
接下來按F5除錯,此時彈出一個資訊框,選配置任務,選擇後點擊Others,跳出tasks.json(官方文件 )配置檔案,配置一個名為”build“的任務。 直接貼程式碼吧:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks":
[
{
"label": "build",//任務名,和lanuch.json中的"preLaunchTask":"build"一致
"type": "shell",
"command": "g++",
"args":["-g","${workspaceRoot}/${fileBasenameNoExtension}.cpp","-o","${fileBasenameNoExtension}.out"],//要編譯的檔案mian_test.cpp,${workspaceRoot}表示vscode所開啟的工作目錄
"problemMatcher":
{
"owner":"cpp",
"fileLocation":["relative","${workspaceRoot}"],
"pattern":
{
"regexp": "^([^\\\\s].*)\\\\((\\\\d+,\\\\d+)\\\\):\\\\s*(.*)$",
"file": 1,
"line":2,
"column":3,
"severity": 4,
"location": 2,
"message": 5
}
}
}
]
}
五、解決一點小問題
接下來繼續按F5,彈出一個問題:“Unable to start debugging. No terminal is available to launch the debugger. Please install Gnome Terminal or XTerm”
很好解決,只需要到deepin商店中下載gnome-terminal即可。
至此,環境已經初步建成。
六、細節
Ctrl+shift+d是編譯,F5是編譯+除錯。
七、下一步安排
研究編譯器clang的配置方法、