Ubuntu系統使用vscode寫C 的方法

2021-12-30 12:40:35 字數 1837 閱讀 5056

vscode 需要改寫 .vscode/launch.json 和 .vscode/tasks.json,前者描述除錯工程環境,如何啟動任務,後者定義編譯方法

假定乙個簡單工程

/* solution.h */

class solution ;

/* solution.cpp */

#include

#include "solution.h"

void solution::say()

/* main.cpp */

#include "solution.h"

int main () 用vscode開啟乙個工程資料夾,然後 檢視->除錯(ctrl+shift+d)選擇編譯環境

選擇好後會自動生成乙個launch.json檔案,修改「program」和「prelaunchtask」即可

/hello", // 修改輸出程式路徑

"args": ,

"stopatentry": false,

"cwd": "$",

"environment": ,

"externalconsole": true,

"prelaunchtask": "build_hello", // 新增 "prelaunchtask" 編譯任務

"mimode": "gdb",

"setupcommands": []}

]}

專案說明

name

配置名稱,會在啟動配置的下拉列表中顯示

type

配置型別,只能為cppdbg

request

請求型別,可以為launch或attach

program

將要除錯的程式的路徑

args

除錯時傳遞給程式的命令列引數

stopatentry

設為true程式會暫停在入口處

cwd除錯程式時的工作目錄

environment

環境變數

externalconsole

除錯時是否顯示控制台視窗

mimode

指定連線的偵錯程式,可以為gdb或lldb

prelaunchtask

除錯開始前執行的任務,一般為編譯程式

ctrl+shift+p 搜尋選擇 「配置任務」

修改生成的 tasks.json為

},"group": }]

}「type」 可以選 shell 或 process

如果是 shell ,那麼 「command」 的內容會被解釋成一條shell命令,否則會被理解為執行乙個程式 官方使用更為靈活的 shell + sh 的方式

「type」=shell,」command」=」xx.sh」,在s**件裡實現複雜的編譯方法 這裡我使用了 shell + make 的方式

工程目錄下再寫乙個標準的 makefile

/* makefile */

hello : main.o solution.o

g++ -o hello main.o solution.o

main.o : main.cpp solution.h

g++ -g -c main.cpp

solution.o : solution.h solution.cpp

g++ -g -c solution.cpp

clean :

rm main.o solution.o hello完成 tasks.json 後 ctrl+shift+b 編譯 **插入斷點,f5開始除錯,f11單步(makefile 的輸出和launch.json的「program」要一致

Ubuntu上構建Godot的VS Code工程

對於windows程式設計師來說,都喜歡在ide上開發。vs code是微軟開發的,技術實力和號召力毋庸置疑,所以在linux上用vs code是乙個非常好的選擇。我使用的組合是windows vmware workstation 16 player ubuntu 20.04.2.0。由於需要安裝各...

docker 使用ubuntu 系統

1 安裝ubuntu系統命令 docker pull ubuntu 這是乙個極度精簡的系統,連最基本的wget命令都沒有 所以先要apt get update公升級系統和安裝apt get install wget命令 2 執行進入ubuntu系統命令 docker run ti ubuntu ba...

ubuntu系統使用ssh鏈結

ubuntu系統不自帶ssh的,必須要自己去安裝 先看看系統是否已經裝了ssh服務 ssh localhost ssh connect to host localhost port 22 connection refused 表示系統尚未安裝ssh服務。那麼直接安裝 使用下面的命令 sudo apt...