链接OpenCV静态库相关错误

问题1

以前都是用***.so动态库,这次换成了***.a静态库,就用了一个opencv读图的功能,make的时候报这样的错误:

./opencv3.4.13/lib/libopencv_core.a(persistence_c.cpp.obj): In function `cvOpenFileStorage_(CvFileStorage*&, char const*, CvMemStorage*, int, char const*)':
persistence_c.cpp:(.text._ZL18cvOpenFileStorage_RP13CvFileStoragePKcP12CvMemStorageiS3_+0xa0c): undefined reference to `gzopen'
./opencv3.4.13/lib/libopencv_core.a(persistence.cpp.obj): In function `icvPuts(CvFileStorage*, char const*)':
persistence.cpp:(.text._Z7icvPutsP13CvFileStoragePKc+0x1ac): undefined reference to `gzputs'
./opencv3.4.13/lib/libopencv_core.a(persistence.cpp.obj): In function `icvGets(CvFileStorage*, char*, int)':
persistence.cpp:(.text._Z7icvGetsP13CvFileStoragePci+0x180): undefined reference to `gzgets'
./opencv3.4.13/lib/libopencv_core.a(persistence.cpp.obj): In function `icvEof(CvFileStorage*)':
persistence.cpp:(.text._Z6icvEofP13CvFileStorage+0x28): undefined reference to `gzeof'
./opencv3.4.13/lib/libopencv_core.a(persistence.cpp.obj): In function `icvCloseFile(CvFileStorage*)':
persistence.cpp:(.text._Z12icvCloseFileP13CvFileStorage+0x18): undefined reference to `gzclose'
./opencv3.4.13/lib/libopencv_core.a(persistence.cpp.obj): In function `icvRewind(CvFileStorage*)':
persistence.cpp:(.text._Z9icvRewindP13CvFileStorage+0x18): undefined reference to `gzrewind'
./opencv3.4.13/lib/libopencv_core.a(persistence.cpp.obj): In function `icvFSFlush(CvFileStorage*)':
persistence.cpp:(.text._Z10icvFSFlushP13CvFileStorage+0x158): undefined reference to `gzputs'
./opencv3.4.13/lib/libopencv_core.a(persistence.cpp.obj): In function `icvClose(CvFileStorage*, cv::String*)':
persistence.cpp:(.text._Z8icvCloseP13CvFileStoragePN2cv6StringE+0xb0): undefined reference to `gzclose'

发现gzopen,gzclose,gzputs都是zlib里面的函数,libopencv_core.a用到了zlib里边的一些功能,看来是要要链接zlib库,然而编译的时候没找到这个库,现在来安装zlib然后加上去。

zlib在opencv的3rdparty里面有,编译OpenCV的时候勾上它:
在这里插入图片描述
编译成功后在对应了路径就会有:
在这里插入图片描述
得到libzlib.a后,在Makeflie里面链接库的地方加上-lzlib
重要的是,要注意顺序,加在-lopencv_core后面。(静态库的顺序是有影响的)

大概像这样写:

gcc main.c -lopencv_core -lzlib -o main



问题2

error while loading shared libraries: ../../lib/libopencv_core.so: cannot open shared object file: No such file or directory

用下面的命令查看信息:

readelf -d libopencv_highgui.so
Dynamic section at offset 0x50580 contains 30 entries:
  Tag Type Name/Value
 0x00000001 (NEEDED) Shared library: [../../lib/libopencv_core.so]
 0x00000001 (NEEDED) Shared library: [../../lib/libopencv_imgproc.so]
 0x00000001 (NEEDED) Shared library: [libstdc++.so.6]
 0x00000001 (NEEDED) Shared library: [libm.so.6]
 0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]
 0x00000001 (NEEDED) Shared library: [libc.so.6]
 0x0000000c (INIT) 0xa410
 0x0000000d (FINI) 0x49ed4
 0x00000019 (INIT_ARRAY) 0x50000
 0x0000001b (INIT_ARRAYSZ) 12 (bytes)
 0x0000001a (FINI_ARRAY) 0x5000c
......

发现它找的是相对路径../../lib/libopencv_core.so

参考:
https://www.codenong.com/cs106665290/
http://blog.chinaunix.net/uid-27134408-id-5122776.html

出现问题的原因是因为配置cmake时填写的时arm-linux,应该填写Linux,进行重新配置编译生成库就行了

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值