最近做OpenCV的交叉编译,参考了国内某大大的博客之后,成功编译出动态库文件,但运行时总是报错:
/rom/data/avt/test/cardetect/testso: error while loading shared libraries: ../../lib/libopencv_core.so: cannot open shared object file: No such file or directory
分析认为是运行时libopencv_highgui.so和
libopencv_objdetect.so链接
../../lib/libopencv_core.so时找不到库文件造成的。问题就出在
libopencv_core.so前面奇怪的"../../lib/"相对路径。用readelf -d查看libopencv_highgui.so文件信息:
-
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
-
......
果然
libopencv_highgui.so链接core库的时候把../../lib也加上去了。
我研究了半天也没找到这个路径是在哪里可以设置的,突然想到,google上国外友人似乎很少遇到这个问题。于是按照这篇文章又重编了opencv:
其中编译过程中需要在toolchain.cmake中增加一项配置:
-
set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
否则cmake会从root path中寻找make和gcc\g++使用,这会产生类似expect ")"的错误信息。
之后按照步骤编译出动态库,再用readelf查看一下:
-
readelf -d libopencv_objdetect.so
-
-
Dynamic section at offset 0x107628 contains 35 entries:
-
Tag Type Name/Value
-
0x00000001 (NEEDED) Shared library: [libopencv_core.so.2.4]
-
0x00000001 (NEEDED) Shared library: [libopencv_imgproc.so.2.4]
-
0x00000001 (NEEDED) Shared library: [libopencv_highgui.so.2.4]
-
0x00000001 (NEEDED) Shared library: [libdl.so.2]
-
0x00000001 (NEEDED) Shared library: [libpthread.so.0]
-
0x00000001 (NEEDED) Shared library: [librt.so.1]
-
0x00000001 (NEEDED) Shared library: [libstdc++.so.6]
-
.........
这样放到arm下面运行,就会从当前目录下正确的找到core库了。
阅读(3416) | 评论(0) | 转发(0) |