Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1685468
  • 博文数量: 511
  • 博客积分: 967
  • 博客等级: 准尉
  • 技术积分: 2560
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-06 14:19
文章分类

全部博文(511)

文章存档

2016年(11)

2015年(61)

2014年(257)

2013年(63)

2012年(119)

分类: 嵌入式

2015-07-15 17:50:46

最近做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文件信息:

点击(此处)折叠或打开

  1. readelf -d libopencv_highgui.so

  2. Dynamic section at offset 0x50580 contains 30 entries:
  3.   Tag Type Name/Value
  4.  0x00000001 (NEEDED) Shared library: [../../lib/libopencv_core.so]
  5.  0x00000001 (NEEDED) Shared library: [../../lib/libopencv_imgproc.so]
  6.  0x00000001 (NEEDED) Shared library: [libstdc++.so.6]
  7.  0x00000001 (NEEDED) Shared library: [libm.so.6]
  8.  0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]
  9.  0x00000001 (NEEDED) Shared library: [libc.so.6]
  10.  0x0000000c (INIT) 0xa410
  11.  0x0000000d (FINI) 0x49ed4
  12.  0x00000019 (INIT_ARRAY) 0x50000
  13.  0x0000001b (INIT_ARRAYSZ) 12 (bytes)
  14.  0x0000001a (FINI_ARRAY) 0x5000c
  15. ......
果然libopencv_highgui.so链接core库的时候把../../lib也加上去了。
我研究了半天也没找到这个路径是在哪里可以设置的,突然想到,google上国外友人似乎很少遇到这个问题。于是按照这篇文章又重编了opencv:

其中编译过程中需要在toolchain.cmake中增加一项配置:

点击(此处)折叠或打开

  1. set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )

否则cmake会从root path中寻找make和gcc\g++使用,这会产生类似expect ")"的错误信息。
之后按照步骤编译出动态库,再用readelf查看一下:

点击(此处)折叠或打开

  1. readelf -d libopencv_objdetect.so

  2. Dynamic section at offset 0x107628 contains 35 entries:
  3.   Tag Type Name/Value
  4.  0x00000001 (NEEDED) Shared library: [libopencv_core.so.2.4]
  5.  0x00000001 (NEEDED) Shared library: [libopencv_imgproc.so.2.4]
  6.  0x00000001 (NEEDED) Shared library: [libopencv_highgui.so.2.4]
  7.  0x00000001 (NEEDED) Shared library: [libdl.so.2]
  8.  0x00000001 (NEEDED) Shared library: [libpthread.so.0]
  9.  0x00000001 (NEEDED) Shared library: [librt.so.1]
  10.  0x00000001 (NEEDED) Shared library: [libstdc++.so.6]
  11. .........
这样放到arm下面运行,就会从当前目录下正确的找到core库了。



阅读(4638) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~