TLDR:
在arm上运行程序(在Ubuntu上交叉编译)使用openCV生成错误:加载共享库时出错:/lib/libopencv_highgui.so.3.1:内部错误
我发布了here和here,但我没有运气,所以我在这里尝试。
我在this guide之后交叉编译了OpenCV,并使用cmake
和make
构建了this sample program:
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
if ( argc != 2 )
{
printf("usage: DisplayImage.out <Image_Path>\n");
return -1;
}
Mat image;
image = imread( argv[1], 1 );
if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
return 0;
}
(主持人:Ubuntu,目标:手臂)
当我将二进制文件和lib复制到目标并运行二进制文件时,我收到此错误:
./ DisplayImage:加载共享库时出错:/lib/libopencv_highgui.so.3.1:内部错误
这是我的 CMakeLists.txt :
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
set( CMAKE_SYSTEM_NAME Linux )
set( CMAKE_SYSTEM_PROCESSOR arm )
set( CMAKE_C_COMPILER arm-linux-gnueabihf-gcc )
set( CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++ )
编辑2:我忘了在CMakeLists.txt中提及以下内容:
SET( GCC_COVERAGE_LINK_FLAGS "-Wl,--dynamic-linker=/lib/ld-linux.so.3")
SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}" )
如果没有这两行,我会得到-sh: ./DisplayImage: not found
。所以我添加它们告诉程序在哪里找到链接器。它适用于其他不使用OpenCV的程序...
这不是“openCV program compile error “libopencv_core.so.2.4: cannot open shared object file: No such file or directory” in ubuntu 12.04”的重复,因为我没有收到“没有这样的文件或目录......”
为什么我得到这个或如何获得有关错误的更多信息?
我尝试在程序上运行strace
,我得到了:
open("/home/my_host_user/opencv/opencv/platforms/linux/my_build_dir/lib/vfp/libopencv_highgui.so.3.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/home/my_host_user/opencv/opencv/platforms/linux/my_build_dir/lib/vfp", 0x7e9e94f0) = -1 ENOENT (No such file or directory)
... //and more like these
所以它仍然与主机名相关联(参见 my_host_user 和 my_build_dir - 这些是我主机中的目录)
编辑1:
我也因strace
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
编辑3:
在Ubuntu中对程序运行ldd
会产生not a dynamic executable
(我想因为它不是为Ubuntu构建的)。所以我尝试了readelf -d DisplayImage | grep NEEDED
,我得到了:
0x00000001 (NEEDED) Shared library: [libopencv_highgui.so.3.1]
0x00000001 (NEEDED) Shared library: [libopencv_imgcodecs.so.3.1]
0x00000001 (NEEDED) Shared library: [libopencv_core.so.3.1]
0x00000001 (NEEDED) Shared library: [libstdc++.so.6]
0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x00000001 (NEEDED) Shared library: [libc.so.6]
0x00000001 (NEEDED) Shared library: [ld-linux-armhf.so.3]
除了ld-linux-armhf.so.3
之外,我在目标上找到了所有这些内容。
很抱歉很长的帖子......