I want to cross-compile C++-applications for the raspi using the rpi-tools, CMake and a raspbian sysroot I'm exporting via nfs from a running raspi. My CMake-toolchain-file is OK, header-files and most of the libraries are correctly detecting inside my sysroot-mount.

Except that there is one issue which seems to be new with raspbian stretch?

The problem I'm facing is that the some library-files located at /usr/lib/arm-linux-gnueabihf/ are a link to the real file located at /lib/arm-linux-gnueabihf/. This link is done with an absolute path.

This is a problem when using the sysroot-mount via NFS (my moint-point is /mnt/rpi-rootfs). But this will also be a problem when doing cross-compilation with a copy of sysroot if sysroot contains links like that.

My CMakeFiles are looking for rt for example and as librt is linked to /lib/arm-linux-gnueabihf/librt.so.1. This file does not exist (it is actually located in /mnt/rpi-rootfs/lib/arm-linux-gnueabihf/librt.so.1) cmake fails.

Where is my mistake? Is there something I can do with the raspbian-distribution? Is this a bug? Is it a feature?


1 Answer 1


As a workaround I used symlinks to correct it:

cd /usr/lib/arm-linux-gnueabihf
symlinks -c .

absolute: /usr/lib/arm-linux-gnueabihf/libanl.so -> /lib/arm-linux-gnueabihf/libanl.so.1
changed:  /usr/lib/arm-linux-gnueabihf/libanl.so -> ../../../lib/arm-linux-gnueabihf/libanl.so.1

Previous answer: realpath doesn't work as expected, it adds a ../ too much.

I created a small script which replaces absolute links with relative ones in the current-directory.


for L in $(find -type l)
    ABSOLUTE=$(readlink $L)

    if [[ $ABSOLUTE =~ ^/ ]] # if it starts with a / it is an absolute link
        RELATIVE=$(realpath --relative-to=$L -s $ABSOLUTE)
        echo fixing link of $L to $ABSOLUTE with $RELATIVE
        sudo ln -sf $RELATIVE $L

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.