TLDR:
Running a program on arm (cross-compiled on Ubuntu) which uses openCV generates error: error while loading shared libraries: /lib/libopencv_highgui.so.3.1: internal error
I posted here and here but I've got no luck so I'm trying here.
I cross-compiled OpenCV for arm following this guide, and built this sample program using cmake
and make
:
#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;
}
(host: Ubuntu, target: arm)
When I copy the binary and the libs to the target and run the binary I get this error:
./DisplayImage: error while loading shared libraries: /lib/libopencv_highgui.so.3.1: internal error
This is my 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++ )
edit 2: I forgot to mention the following also in 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}" )
Without these 2 lines I get -sh: ./DisplayImage: not found
. So I add them to tell the program where to find the linker. It works with other programs that don't use OpenCV...
This is not a duplicate of "openCV program compile error “libopencv_core.so.2.4: cannot open shared object file: No such file or directory” in ubuntu 12.04" because I'm not getting a "No such file or directory..."
Why am I getting this or how can I get more information about the error?
I tried running strace
on the program and I got:
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
So it's like something is still linked with the host machine names (see my_host_user and my_build_dir - these are directories in my host machine)
edit 1:
I also get this error with strace
:
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
edit 3:
Running ldd
on the program in Ubuntu produces not a dynamic executable
(I guess becaues it's not built for Ubuntu). So I tried readelf -d DisplayImage | grep NEEDED
and I got:
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]
I found all of them on my target except ld-linux-armhf.so.3
.
Sorry for the long post...