我在当前目录下有3个文件,分别是object_detector.h,object_detector.cpp和main.cpp。
其中,main.cpp的编译要依赖于objector.cpp生成的库。我用VSCODE编译object_detector.cpp好后,生成object_detector的二进制文件,但是当编译main时,却链接不上,后面我灵机一动,将:
object_detector重命名为libobject_detector.so,这样就能链接上啦。
最后,附上我的VSCODE的配置文件:
task.json:
{
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
//"-shared", //编译动态库时用,取消注释
//"-fPIC", //编译动态库时取消注释
"-g",
"-std=c++11",
//"${fileDirname}/*.cpp", //multi-files
"${file}", //single-file
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
//for opencv
"-I", "/usr/local/include",
"-I", "/usr/local/include/opencv",
"-I", "/usr/local/include/opencv4",
"-L", "/usr/local/lib", //库文件所在路径
"-l", "opencv_aruco",
"-l", "opencv_bgsegm", //库下的文件
"-l", "opencv_bioinspired",
"-l", "opencv_calib3d",
"-l", "opencv_ccalib",
"-l", "opencv_core",
"-l", "opencv_datasets",
"-l", "opencv_dnn_objdetect",
"-l", "opencv_dnn",
"-l", "opencv_dpm",
"-l", "opencv_face",
"-l", "opencv_features2d",
"-l", "opencv_flann",
"-l", "opencv_freetype",
"-l", "opencv_fuzzy",
"-l", "opencv_hfs",
"-l", "opencv_highgui",
"-l", "opencv_imgcodecs",
"-l", "opencv_img_hash",
"-l", "opencv_imgproc",
"-l", "opencv_line_descriptor",
"-l", "opencv_ml",
"-l", "opencv_objdetect",
"-l", "opencv_optflow",
"-l", "opencv_phase_unwrapping",
"-l", "opencv_photo",
"-l", "opencv_plot",
"-l", "opencv_reg",
"-l", "opencv_rgbd",
"-l", "opencv_saliency",
"-l", "opencv_shape",
"-l", "opencv_stereo",
"-l", "opencv_stitching",
"-l", "opencv_structured_light",
"-l", "opencv_superres",
"-l", "opencv_surface_matching",
"-l", "opencv_text",
"-l", "opencv_tracking",
"-l", "opencv_videoio",
"-l", "opencv_video",
"-l", "opencv_videostab",
"-l", "opencv_xfeatures2d",
"-l", "opencv_ximgproc",
"-l", "opencv_xobjdetect",
"-l", "opencv_xphoto",
"-L", "/home/laijinxiang/LSLAM/Detector", //把自己的动态库所在文件夹加进去
"-l", "object_detector", //要命名成libobject_detector.so才能成功链接上
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
launch.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": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
c_cpp_properties.json:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/include/opencv4"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
116

被折叠的 条评论
为什么被折叠?



