vscode C++遠(yuǎn)程調(diào)試運行(學(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++編譯運行環(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++插件
注意安裝到遠(yuǎn)程主機(jī)上
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 } }, { //刪除二進(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)試運行
在菜單欄選擇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é)束后刪除二進(jìn)制文件。
2.5 調(diào)試F5, 不調(diào)試直接運行Cltr+F5
總結(jié)
到此這篇關(guān)于vscode C++遠(yuǎn)程調(diào)試運行(學(xué)習(xí)C++用)的文章就介紹到這了,更多相關(guān)vscode C++遠(yuǎn)程調(diào)試運行內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Linux搭建C++開發(fā)調(diào)試環(huán)境的方法步驟
- c++代碼調(diào)試方式的幾點建議
- 解決vscode下調(diào)試c/c++程序一閃而過的問題(Windows)
- vscode配置遠(yuǎn)程開發(fā)環(huán)境并遠(yuǎn)程調(diào)試運行C++代碼的教程
- VSCode遠(yuǎn)程開發(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)文章
Windows下搭建FFmpeg開發(fā)調(diào)試環(huán)境的詳細(xì)步驟
這篇文章主要介紹了Windows下搭建FFmpeg開發(fā)調(diào)試環(huán)境,本文以VS2017為例一步步介紹怎么搭建一個可供單步調(diào)試的FFmpeg項目,需要的朋友可以參考下2022-07-07C++中fstream,ifstream及ofstream用法淺析
這篇文章主要介紹了C++中fstream,ifstream及ofstream用法,適合C++初學(xué)者學(xué)習(xí)文件流的操作,需要的朋友可以參考下2014-08-08C++數(shù)據(jù)結(jié)構(gòu)AVL樹全面分析
今天的這一篇博客,我要跟大家介紹一顆樹——AVL樹,它也是一顆二叉搜索樹,它就是在二叉搜索樹中加了一個平衡因子的概念在里面,下面我就來和大家聊一聊這棵樹是個怎么樣的樹2021-10-10