帝国cms地方门户网站模板,网站透明导航代码,wordpress 微商城模板,网站开发维护协议本文记录win平台使用vscode远程连接ubuntu server服务器下#xff0c;如何配置c/c调试环境。
过程
1. 服务器配置编译环境
这里的前置条件是vscode已经能够连接到服务器#xff0c;第一步安装编译构建套件#xff08;gcc、g、make、链接器等#xff09;和调试器#xf…本文记录win平台使用vscode远程连接ubuntu server服务器下如何配置c/c调试环境。
过程
1. 服务器配置编译环境
这里的前置条件是vscode已经能够连接到服务器第一步安装编译构建套件gcc、g、make、链接器等和调试器sudo apt-get install build-essential gdb。
2. 配置vscode
安装c/c拓展 CtrilShiftP调出命令行Reload Window快速重启窗口
生成.vscode文件夹下默认配置主要包含如下三个文件
CtrlShiftP调出命令行
命令行C/C编辑配置(JSON) // c_cpp_properties.json
命令行任务配置任务 // task.json
命令行调试添加配置 //launch.json3. 创建源文件设置具体json配置项
源文件如下
// main.cpp
#include iostream
#include iomanip // 用于控制输出格式int main() {for (int i 1; i 9; i) { // 外层循环控制行for (int j 1; j i; j) { // 内层循环控制列// 打印乘法表的一项setw(4)设置输出宽度为4以保持对齐std::cout j x i std::setw(2) i*j ;}std::cout std::endl; // 每打印完一行后换行}return 0;
}
配置项如下说明以注释形式给出
// c_cpp_properites.json 默认的
{configurations: [{name: Linux,includePath: [${workspaceFolder}/**],defines: [],compilerPath: /usr/bin/gcc,cStandard: c17,cppStandard: gnu14,intelliSenseMode: linux-gcc-x64}],version: 4
}
// launch.json
{// 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。// 欲了解更多信息请访问: https://go.microsoft.com/fwlink/?linkid830387version: 0.2.0,configurations: [{name: (gdb) 启动,type: cppdbg,request: launch,program: ${workspaceFolder}/main.dbg, // 调试程序名args: [],stopAtEntry: false,cwd: ${fileDirname}, // 工作目录environment: [],externalConsole: false,MIMode: gdb,setupCommands: [{description: 为 gdb 启用整齐打印,text: -enable-pretty-printing,ignoreFailures: true},{description: 将反汇编风格设置为 Intel,text: -gdb-set disassembly-flavor intel,ignoreFailures: true}],preLaunchTask: build_dbg // 预执行任务}]
}// tasks.json
{// See https://go.microsoft.com/fwlink/?LinkId733558// for the documentation about the tasks.json formatversion: 2.0.0,tasks: [{label: build_dbg,type: shell,command: g *.cpp -g -o main.dbg // 任务这里使用g编译输出文件}]
}下断点F5调试vsc将根据launch.json中的配置使用gdb调试main.gdb在此之前执行preLaunchTask即build_dbgbuild_dbg在task.json中配置执行“g *.cpp -g -o main.dbg”