'RPi Cross Compiling: how to link dynamic libraries
I try to cross compile from an x86_64 windows machine to a Raspberry Pi 4B running Raspberry OS lite and i already managed to run a "hello world" with my toolchain. Now, i want to create more complex programs which include dynamic libraries, and i fail in creating a makefile which links the dynamic libraries correctly. All libraries needed are available on the host as well as on the target device. When i link the makefile on the host:
LIBRARIES := C:/SysGCC/raspberry64/aarch64-linux-gnu/sysroot/lib/aarch64-linux-gnu/libdl.so.2
The program compiles properly, but the execution on the target rises the error: "error while loading shared libraries: no such file or directory". Which makes abosulte sense.
But, when i link the libraries of the target:
LIBRARIES := /opt/Vimba_5_1/VimbaC/DynamicLib/arm_64bit/libVimbaC.so /usr/lib/aarch64-linux-gnulibdl.so.2
The error "No such file or directory" arises within the compilation process.
My question is: How can i link the dynamic libraries properly?
Thanks in advance!
Solution 1:[1]
lets try
on host machine (windows) :
add C:/SysGCC/raspberry64/aarch64-linux-gnu/sysroot/lib/aarch64-linux-gnu/ to your environment variable
My Computer>Properties>Advanced>Environment Variables>System Variables>Path>Edit>Variable Value
on target machine (linux)
env LD_LIBRARY_PATH=/opt/Vimba_5_1/VimbaC/DynamicLib/arm_64bit/ ./your_program
if it work -> you can add the path to library searching path with ldconfig https://blog.andrewbeacock.com/2007/10/how-to-add-shared-libraries-to-linuxs.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | long.kl |
