linux下visual studio code配置c++调试环境实例

test1.cpp源码如下:

#include <stdio.h>

#include <libxl.h>

using namespace libxl;

int main()

{

Book* book = xlCreateBook();

if(book)

{

Sheet* sheet = book->addSheet("Sheet1");

if(sheet)

{

sheet->writeStr(2, 1, "Hello, world!");

sheet->writeNum(3, 1, 1000);

}

book->save("example.xls");

book->release();

}

}

luanch.json代码如下:

{

// Use IntelliSense to learn about possible attributes.

// Hover to view descriptions of existing attributes.

// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387

"version": "0.2.0",

"configurations": [

{

"name": "test1",

"type": "cppdbg",

"request": "launch",

"program": "${workspaceFolder}/test1",

"args": [],

"stopAtEntry": false,

"cwd": "${workspaceFolder}",

"environment": [],

"externalConsole": false,

"MIMode": "gdb",

"setupCommands": [

{

"description": "Enable pretty-printing for gdb",

"text": "-enable-pretty-printing",

"ignoreFailures": true

}

],

"preLaunchTask": "build",

"miDebuggerPath": "/usr/bin/gdb"

}

]

}

task.json中代码如下:

{

// See https://go.microsoft.com/fwlink/?LinkId=733558

// for the documentation about the tasks.json format

"version": "2.0.0",

"tasks": [

{

"label": "build",

"type": "shell",

"command": "cd ${workspaceFolder} && g++ test1.cpp -I/home/program/libxl-3.8.8.2/include_c/ -L/home/program/libxl-3.8.8.2/lib/ -lxl -o test1}"

}

]

}