问题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,进行重新配置编译生成库就行了