vscode C++遠(yuǎn)程調(diào)試運(yùn)行(學(xué)習(xí)C++用)
目標(biāo):
連接遠(yuǎn)程主機(jī) (ssh)
配置C++編譯環(huán)境 (輸出結(jié)果后刪除二進(jìn)制文件)

步驟:
安裝Remote SSH,連接遠(yuǎn)程主機(jī)
Visual Studio 官方文檔
https://code.visualstudio.com/docs/remote/ssh
圖標(biāo)
2. 配置C++編譯運(yùn)行環(huán)境
主要參考下面兩篇文檔
https://code.visualstudio.com/docs/cpp/config-wsl
https://code.visualstudio.com/docs/editor/tasks
2.1 新建一個(gè)C++源文件HelloWorld.cpp(測(cè)試用)
#include <iostream>
int main(){
std::cout<<"Hello World!\n";
return 0;
}
2.2 安裝 Microsoft C/C++插件
注意安裝到遠(yuǎn)程主機(jī)上
2.3 創(chuàng)建tasks.json文件
從菜單欄選擇Terminal>Configure Default Build Task, 在下拉欄里選擇C/C++: g++ build active file. 這會(huì)生成tasks.json文件。

按需修改tasks.json文件:
{
"tasks": [
{
//編譯源文件
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-std=c++11", //C++版本, 可不加
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{ //刪除二進(jìn)制文件
"type": "shell",
"label": "delete output file",
"command": "rm",
"args": [
"${fileDirname}/${fileBasenameNoExtension}"
],
"presentation": {
"reveal": "silent", //刪除過程不切換終端(專注程序輸出)
}
}
],
"version": "2.0.0"
}
2.4 創(chuàng)建launch.json用于調(diào)試運(yùn)行
在菜單欄選擇Debug>Add Configuration, 選擇C++ (GDB/LLDB), 在下拉欄中選擇g++ build and debug active file.

這會(huì)創(chuàng)建launch.json, 編輯如下
{
"version": "0.2.0",
"configurations": [
{
"name": "g++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++ build active file",
"postDebugTask": "delete output file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
注:這里“preLaunchTask”調(diào)用tasks.json文件里定義的“g++ build and debug active file”任務(wù), “postDebugTask”調(diào)用“delete output file”任務(wù)用來在程序運(yùn)行結(jié)束后刪除二進(jìn)制文件。
2.5 調(diào)試F5, 不調(diào)試直接運(yùn)行Cltr+F5
總結(jié)
到此這篇關(guān)于vscode C++遠(yuǎn)程調(diào)試運(yùn)行(學(xué)習(xí)C++用)的文章就介紹到這了,更多相關(guān)vscode C++遠(yuǎn)程調(diào)試運(yùn)行內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Linux搭建C++開發(fā)調(diào)試環(huán)境的方法步驟
- c++代碼調(diào)試方式的幾點(diǎn)建議
- 解決vscode下調(diào)試c/c++程序一閃而過的問題(Windows)
- vscode配置遠(yuǎn)程開發(fā)環(huán)境并遠(yuǎn)程調(diào)試運(yùn)行C++代碼的教程
- VSCode遠(yuǎn)程開發(fā)調(diào)試服務(wù)器c/c++代碼
- ubunt18.04LTS+vscode+anaconda3下的python+C++調(diào)試方法
- C++運(yùn)算符重載實(shí)例代碼詳解(調(diào)試環(huán)境 Visual Studio 2019)
- 詳解AndroidStudio3.0開發(fā)調(diào)試安卓NDK的C++代碼
- C++調(diào)試記錄與心得分享
- 詳解C++的反調(diào)試技術(shù)與繞過手法
相關(guān)文章
C++異步數(shù)據(jù)交換實(shí)現(xiàn)方法介紹
這篇文章主要介紹了C++異步數(shù)據(jù)交換實(shí)現(xiàn)方法,異步數(shù)據(jù)交換,除了阻塞函數(shù) send() 和 recv() 之外,Boost.MPI 還支持與成員函數(shù) isend() 和 irecv() 的異步數(shù)據(jù)交換2022-11-11
C語言中while與do-while的介紹與注意事項(xiàng)
對(duì)于C語言中的while與do-while,相信很多都再熟悉不過了,最近在工作中就用到了,所以想著總結(jié)一下,方便自己或者有需要的朋友們參考借鑒,文中通過示例代碼介紹的很詳細(xì),感興趣的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧。2016-10-10
C++中字符串與整型及浮點(diǎn)型轉(zhuǎn)換全攻略
C++算法刷題等過程中經(jīng)常會(huì)遇到字符串與數(shù)字類型的轉(zhuǎn)換,在這其中雖然樸素的算法有不少,但是對(duì)于double等類型還是可以說遇到一些麻煩,所以今天就來說說使用C++標(biāo)準(zhǔn)庫中的函數(shù)實(shí)現(xiàn)這些功能。感興趣的小伙伴一起參與閱讀吧2021-09-09
C語言實(shí)現(xiàn)簡(jiǎn)單的聊天室功能
這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)簡(jiǎn)單的聊天室功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-06-06

