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

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

andrepc gravatar image

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

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/$ ./  ./ error while loading shared libraries: 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/ is the dynamic linker, ignoring

ldconfig: /lib/ is the dynamic linker, ignoring ->

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

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


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

SOFTWARE_SRC = $(wildcard src/software/*.cpp)
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



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


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