參考網址:
https://www.cnblogs.com/lidabo/p/5888997.html 在Linux中使用VS Code編譯調試C++項目
https://www.jianshu.com/p/2700f2b93b14 2019 linux下vscode C++配置
https://www.cnblogs.com/dotnetcrazy/p/6661921.html 1.跨平台開發之~ VSCode開發第一個C程序
1、在vscode里面下載c/c++官方插件:
注意:C / C ++擴展不包括C ++編譯器或調試器。您需要安裝這些工具或使用計算機上已安裝的工具。流行的C ++編譯器是用於Windows的mingw-w64,用於macOS的XCode的 Clang 和用於Linux的GCC。確保您的編譯器可執行文件位於您的平台路徑中,以便擴展程序可以找到它。該擴展還支持Windows的Windows子系統。
C/C++ 為必裝,提供C/C++支持
Code Runner 必裝,提供編譯后程序的運行環境
C/C++ Snippets 建議 提供一些常用的C/C++片段,如for(;;){},安裝后寫代碼方便(tip.如果想要添加自己寫的代碼段可以點左下角齒輪->用戶代碼片段)
EPITECH C/C++ Headers 為C/C++文件添加頭部(包括作者、創建和修改日期等),並為.h頭文件添加防重復的宏
File Templates 文件模板,可以自己添加文件模板
GBKtoUTF8 GBK 編碼文件轉換為UTF-8
Include Autocomplete 頭文件自動補全
One Dark Pro 一個好看的vscode主題
Easy C++ projects 提供一個簡單的編譯模式,開啟后只要安裝了C/C++擴展就可以直接編譯運行,建議不用,因為不能自己配置參數
2. 新建測試文件test.c
#include <stdlib.h> #include <stdio.h> void test() { printf("this is my test!!!"); } int main() { printf("this is my test!!!"); return 0; }
3. F5 或者 點擊debug
圖標
4. 點擊設置圖片,出現 選擇環境,選擇 c++

5.生成launch.json
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) Attach", "type": "cppdbg", "request": "attach", "program": "${workspaceFolder}/a.out", "processId": "${command:pickProcess}", "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] }, { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/a.out", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
6.Ctrl+Shift+B,輸入Task 選擇Others 添加tasks.json
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "c++", "type": "shell", "command": "g++", "args": ["-g", "/home/hkjc/Desktop/projects/C/test.c"], "group": { "kind": "build", "isDefault": true } } ] }
7.Ctrl+Shift+B生成a.out, F5即可調試 !
/***************************************************多個文件編譯******************************************************/
https://blog.csdn.net/qq_34347375/article/details/81137962
1. 打開設置找到 code-runner.executorMap
因為我們是通過makefile文件來進行編譯鏈接源程序的,所以在這里更改如下:
"c": "cd $dir && make $fileNameWithoutExt && ./$fileNameWithoutExt && make clean",
"cpp": "cd $dir && make $fileNameWithoutExt && ./$fileNameWithoutExt && make clean",