Reputation: 77
I am trying to cross-compile odas library for Raspberry PI. The code actually builds out of the box on the platform (either Raspberry PI, or Ubuntu box). However, when I am trying to cross compile the same code using this tool chain file (the whole thing started in the previous question):
# Cross-compilation system information
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR "arm")
# Specify the cross compiler
SET(CMAKE_C_COMPILER /home/raspberrypi/opt/x-tools/aarch64-rpi3-linux-gnu/bin/aarch64-rpi3-linux-gnu-gcc)
SET(CMAKE_CXX_COMPILER /home/raspberrypi/opt/x-tools/aarch64-rpi3-linux-gnu/bin/aarch64-rpi3-linux-gnu-g++)
# where is the target environment located
set(CMAKE_SYSROOT /home/raspberrypi/sysroot)
set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}")
SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}")
# adjust the default behavior of the FIND_XXX() commands:
# search programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
I am getting a bunch of errors, like
[1/2] Linking C executable bin/odasserver
FAILED: bin/odasserver
: && /home/raspberrypi/opt/x-tools/aarch64-rpi3-linux-gnu/bin/aarch64-rpi3-linux-gnu-gcc --sysroot=/home/raspberrypi/sysroot -g --sysroot=/home/raspberrypi/sysroot CMakeFiles/odasserver.dir/demo/odasserver/main.obj -o bin/odasserver lib/libodas.so -lfftw3f -lasound -lconfig -lpulse-simple -lpulse -lm -lpthread && :
/home/raspberrypi/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: lib/libodas.so: undefined reference to `__pthread_create'
/home/raspberrypi/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: lib/libodas.so: undefined reference to `_dl_wait_lookup_done'
/home/raspberrypi/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: lib/libodas.so: undefined reference to `_dl_init_static_tls'
/home/raspberrypi/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: lib/libodas.so: undefined reference to `__pointer_chk_guard_local'
/home/raspberrypi/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: lib/libodas.so: undefined reference to `_dl_stack_flags'
/home/raspberrypi/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: lib/libodas.so: undefined reference to `_dl_pagesize'
collect2: error: ld returned 1 exit status
What could be possibly wrong here?
Upvotes: 0
Views: 406
Reputation: 77
long story short - when creating sysroot folder on the host machine, I was using commands like
sudo rsync -avz [email protected]:/lib .
sudo rsync -avz [email protected]:/usr/include usr
sudo rsync -avz [email protected]:/usr/lib usr
sudo rsync -avz [email protected]:/usr/local usr
Apparently, on the target, some symbolic links were pointing outside of the current directory, for example
/usr/lib/aarch64-linux-gnu/libz.so -> /lib/aarch64-linux-gnu/libz.so.1.2.11
So needed to replace absolute symlinks with relative ones. Once this was done, then everything was fine and compiling, and running.
Upvotes: 1