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

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

這會創(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ù)用來在程序運行結(jié)束后刪除二進制文件。
2.5 調(diào)試F5, 不調(diào)試直接運行Cltr+F5
總結(jié)
到此這篇關(guān)于vscode C++遠程調(diào)試運行(學(xué)習(xí)C++用)的文章就介紹到這了,更多相關(guān)vscode C++遠程調(diào)試運行內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Linux搭建C++開發(fā)調(diào)試環(huán)境的方法步驟
- c++代碼調(diào)試方式的幾點建議
- 解決vscode下調(diào)試c/c++程序一閃而過的問題(Windows)
- vscode配置遠程開發(fā)環(huán)境并遠程調(diào)試運行C++代碼的教程
- VSCode遠程開發(fā)調(diào)試服務(wù)器c/c++代碼
- ubunt18.04LTS+vscode+anaconda3下的python+C++調(diào)試方法
- C++運算符重載實例代碼詳解(調(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ù)交換實現(xiàn)方法介紹
這篇文章主要介紹了C++異步數(shù)據(jù)交換實現(xiàn)方法,異步數(shù)據(jù)交換,除了阻塞函數(shù) send() 和 recv() 之外,Boost.MPI 還支持與成員函數(shù) isend() 和 irecv() 的異步數(shù)據(jù)交換2022-11-11

