Error loading OpenCV4 libraries after cross compiling: No such file or directory

asked 2020-08-05 07:34:42 -0600

andrepc gravatar image

updated 2020-08-05 12:47:18 -0600

I'm having problems to load share libraries after cross-compiling my C++ code using Docker Buildx, having a Raspberry Pi Zero W as the target.

After I perform the build, I copy the generated binary to a Raspberry Pi Zero already running and with OpenCV4 installed.

When I run the executable, the following error message is shown:

pi@raspberrypi:/mnt/system/$ ./software.run  ./software.run: error while loading shared libraries: libopencv_freetype.so.4.2: cannot open shared object file: No such file or directory

Despite OpenCV4 being already installed, this particular lib wasn't in the /usr/lib. So, I copied it, run sudo ldconfig but, even after this procedure, my software still cannot find the lib.

I even added the /usr/lib to the path of the system, but, it didn't work.

pi@raspberrypi:/usr/lib $ sudo ldconfig -v | grep libopencv_free
ldconfig: Can't stat /usr/local/lib/arm-linux-gnueabihf: No such file or directory
ldconfig: Path `/lib/arm-linux-gnueabihf' given more than once
ldconfig: Path `/usr/lib/arm-linux-gnueabihf' given more than once
ldconfig: /lib/arm-linux-gnueabihf/ld-2.28.so is the dynamic linker, ignoring

ldconfig: /lib/ld-linux.so.3 is the dynamic linker, ignoring

libopencv_freetype.so.4.2 -> libopencv_freetype.so.4.2.0

pi@raspberrypi:/mnt/system/ $ file software.run 
software.run: ELF 32-bit LSB pie executable, ARM, EABI5 version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=409a24c10761e2b9fd7a310cddfb09c86fb3a207, not stripped

pi@raspberrypi:/mnt/system $ echo $LD_LIBRARY_PATH
/usr/lib

Makefile:

CC = g++
STD = --std=c++14

SOFTWARE_SRC = $(wildcard src/software/*.cpp)
SOFTWARE_BIN = software.run
CV_LIBS = $(shell pkg-config --cflags --libs opencv4)
SOFTWARE_INC = -Iinclude -I/usr/include -I/usr/local/include
SOFTWARE_LDFLAGS = -lraspicam_cv -L/opt/vc/lib -lmmal -lmmal_core -lmmal_util -lwiringPi

all: software-out

software-out:

        $(CC) $(STD) $(SOFTWARE_SRC) -o $(SOFTWARE_BIN) $(CV_LIBS) $(SOFTWARE_INC) $(SOFTWARE_LDFLAGS)

Other software that also uses OpenCV is working properly.

I also build a "Hello World" software just to validate my cross-compiling environment and it is working.

Thank you all in advance

EDIT

After several attempts, I was able to fix the problem by building the libs locally.

I couldn't identify what caused it, but, the libs generated by the Buildx environment weren't working properly in the Raspberry Pi Zero.

I'm building a truly cross-compiling environment to address this issue.

edit retag flag offensive close merge delete