网站链接: element-ui dtcms
当前位置: 首页 > 技术博文  > 技术博文

VSCODE 编译生成动态链接库时需要注意命名

2021/6/27 11:33:03 人评论

我在当前目录下有3个文件,分别是object_detector.h,object_detector.cpp和main.cpp。 其中,main.cpp的编译要依赖于objector.cpp生成的库。我用VSCODE编译object_detector.cpp好后,生成object_detector的二进制文件,但…

我在当前目录下有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
}

 

 

相关资讯

    暂无相关的数据...

共有条评论 网友评论

验证码: 看不清楚?