1、task.json生成.out文件
{
// 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": "g++",
"args": [
"-g", "${file}",
"-std=c++11",
"-I", "/usr/include/eigen3",//头文件目录-I
"-I", "/usr/local/include",
"-I", "/usr/local/include/opencv",
"-I", "/usr/local/include/opencv2",
"-L", "/usr/local/lib",//库文件目录-L
"-l", "opencv_core",
"-l", "opencv_imgcodecs",
"-l", "opencv_features2d",
"-l", "opencv_highgui",
"-l", "opencv_calib3d",
"-o", "${fileBasenameNoExtension}.out"
]
}
]
}
-I参数是用来指定头文件目录,/usr/local/include目录一般是不用指定的,gcc知道去那里找,但是如果头文件在别处,就要用-I参数指定了。
比如头文件放在/usr/**/include/opencv目录里,那编译命令行就要加上"-I",
-I参数可以用相对路径,比如头文件在当前目录,可以用-I.来指定。
-L参数指定库文件所在的目录,一般库文件放在/lib和/usr/lib和/usr/local/lib里的库直接用-l参数就能链接了,但是如果库文件没有放在这三个目录,而是放在其他目录里,这时我们只用-l参数的话,链接还是会出错,出错信息大概是:“/usr/bin/ld: cannot find -lxxx”,也就是链接程序ld在那3个目录里找不到libxxx.so,就需要-L指定库文件目录,-L参数跟着的是库文件所在的目录名。
2、launch.json执行.out文件
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
"args": [
"/home/lzj/slam/ch7/1.png",
"/home/lzj/slam/ch7/2.png",
"/home/lzj/slam/ch7/1_depth.png",
"/home/lzj/slam/ch7/2_depth.png"
],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask": "build",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
这个文件主要是运行程序的,在运行程序之前我们要给程序传参数,把程序需要的参数放到args中。