美文网首页
ubuntu+cmake+opencv 静态库编译和使用

ubuntu+cmake+opencv 静态库编译和使用

作者: FM_1ad7 | 来源:发表于2021-02-25 10:49 被阅读0次

一、 官网下载opencv4.2

https://opencv.org/releases/page/2/

二、编译静态库

cd opencv-4.2/

mkdir static_release

cd static_release/

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_SHARED_LIBS=OFF -D BUILD_SHARED_LIBS=NO -D BUILD_PNG=ON -D BUILD_JASPER=ON -D BUILD_JPEG=ON -D BUILD_TIFF=ON -D BUILD_ZLIB=ON -D WITH_JPEG=ON -D WITH_PNG=ON -D WITH_JASPER=ON -D WITH_TIFF=ON ..

sudo make install

能看到其中一个很明显的改变就是“BUILD_SHARED_LIBS=NO”这个选项,代表了不编译动态库,而是编译静态库。后面那些则是增加一些opencv所依赖的第三方库,也要把他们一起生成才行。

参考连接:https://blog.csdn.net/woainishifu/article/details/79712110

三、cmake 配置库

target_link_libraries(${project_name} ${OPENCV_DIR}/libopencv_imgcodecs.a)

target_link_libraries(${project_name} ${OPENCV_DIR}/libopencv_imgproc.a)

target_link_libraries(${project_name} ${OPENCV_DIR}/libopencv_core.a)

target_link_libraries(${project_name} ${OPENCV_DIR}/libwebp.a)

target_link_libraries(${project_name} ${OPENCV_DIR}/libIlmImf.a)

target_link_libraries(${project_name} ${OPENCV_DIR}/liblibjasper.a)

target_link_libraries(${project_name} ${OPENCV_DIR}/libittnotify.a)

#libopencv

 target_link_libraries(${project_name} "tiff" "jpeg" "png" )

四、遇到问题

缺少:libwebp.a

undefined reference to symbol 'WebPEncodeLosslessBGR'  

缺少:libIlmImf.a

undefined reference to `Imf_opencv::globalThreadCount()'

缺少:liblibjasper.a

/usr/bin/ld: grfmt_jpeg2000.cpp:(.text._ZN2cv13Jpeg2KDecoder8readDataERNS_3MatE+0x20e): undefined reference to `jas_matrix_destroy'

/usr/bin/ld: grfmt_jpeg2000.cpp:(.text._ZN2cv13Jpeg2KDecoder8readDataERNS_3MatE+0x28f): undefined reference to `jas_matrix_create'

/usr/bin/ld: grfmt_jpeg2000.cpp:(.text._ZN2cv13Jpeg2KDecoder8readDataERNS_3MatE+0x2b9): undefined reference to `jas_image_readcmpt'

/usr/bin/ld: grfmt_jpeg2000.cpp:(.text._ZN2cv13Jpeg2KDecoder8readDataERNS_3MatE+0x39a): undefined reference to `jas_image_getcmptbytype'

/usr/bin/ld: grfmt_jpeg2000.cpp:(.text._ZN2cv13Jpeg2KDecoder8readDataERNS_3MatE+0x3af): undefined reference to `jas_image_getcmptbytype'

/usr/bin/ld: grfmt_jpeg2000.cpp:(.text._ZN2cv13Jpeg2KDecoder8readDataERNS_3MatE+0x3c2): undefined reference to `jas_image_getcmptbytype'

/usr/bin/ld: grfmt_jpeg2000.cpp:(.text._ZN2cv13Jpeg2KDecoder8readDataERNS_3MatE+0x416): undefined reference to `jas_cmprof_createfromclrspc'

/usr/bin/ld: grfmt_jpeg2000.cpp:(.text._ZN2cv13Jpeg2KDecoder8readDataERNS_3MatE+0x432): undefined reference to `jas_image_chclrspc'

/usr/bin/ld: grfmt_jpeg2000.cpp:(.text._ZN2cv13Jpeg2KDecoder8readDataERNS_3MatE+0x446): undefined reference to `jas_image_destroy'

/usr/bin/ld: grfmt_jpeg2000.cpp:(.text._ZN2cv13Jpeg2KDecoder8readDataERNS_3MatE+0x45c): undefined reference to `jas_cmprof_destroy'

/usr/bin/ld: grfmt_jpeg2000.cpp:(.text._ZN2cv13Jpeg2KDecoder8readDataERNS_3MatE+0x6fa): undefined reference to `jas_matrix_destroy'

/usr/bin/ld: grfmt_jpeg2000.cpp:(.text._ZN2cv13Jpeg2KDecoder8readDataERNS_3MatE+0x7aa): undefined reference to `jas_cmprof_destroy

缺少:libittnotify.a

undefined reference to `__itt_region_end_ptr__3_0'

五、解决方法

先完整编译opencv 环境 

https://www.jianshu.com/p/f73fcb9a0b1a

再使用 locate 查找 .a静态文件

相关文章

网友评论

      本文标题:ubuntu+cmake+opencv 静态库编译和使用

      本文链接:https://www.haomeiwen.com/subject/xmeyfltx.html