Cloning the root filesystem for cross-compiling

Hello,

I have a general question when cross-compiling a C/C++ application for the Beagle Bone Black.

I am using the cross-compilers provided by Linaro: Linaro Releases . I have managed to make cross-compiling work both for Windows and for Linux systems using a CMake cross-compile build system and the tcf-agent for debugging with Eclipse, but cloning the root filesystem to get all required libraries onto the host system is a tricky process.

I used rsync to do this

rsync -avHAXR --delete-after --info=progress2 --numeric-ids <user_name>@<ip_address>:/{usr,lib} <rootfs_path>

Unfortunately, there seems to be an issue with some symlinks, for example the symlinks libpthread.so and librt.so. These symlinks appear to use absolute paths, and it is necessary, to delete them and repoint them using relative paths. Is there some clean way to clone a sysroot which solves this issue? I expected that CMake can deal with these absolute links when specifying the rootfs properly, but it does not appear to be able to use those symlinks…

rm libpthread.so
rm librt.so
ln -s ../../../lib/arm-linux-gnueabihf/libpthread.so.0 libpthread.so
ln -s ../../../lib/arm-linux-gnueabihf/librt.so.1 librt.so

On Windows, MinGW rsync somehow is not able to copy some files and I need to copy those manually

scp <user_name>@<ip-address>:/lib/arm-linux-gnueabihf/{libc.so.6,ld-linux-armhf.so.3,libm.so.6} <rootfs_path>/lib/arm-linux-gnueabihf
scp <user_name>@<ip-address>:/usr/lib/arm-linux-gnueabihf/{libpthread.so,libc.so,librt.so} <rootfs_path>/usr/lib/arm-linux-gnueabihf

This could propably be solves by using a linux system to clone it properly and then package it as a zip. This is also the easiest way to avoid doing this on different systems. Clone it once properly, and just use a prepared root filesystem with all required libraries. I am just wondering if there is a clean way to clone the rootfs without these “hacks”.

In any case, if this seems useful, maybe I will add a cross-compiling guide using the tcf-agent for the beagle bone black website or github because I did not find anything similar on the website with all necessary steps.

Kind Regards
Robin

The cross-compiling guide can be found here: GitHub - spacefisch/beaglebone-crosscompiling: Cross-compiling and debugging C/C++ applications for the Beaglebone Black with CMake and the TCF-Agent . Tested for Windows and Linux. Maybe it would be easier to do this whole process in a container but I still need to get familiar with docker…

Here’s a Python script to fix symlinks in a cloned sysroot:

#!/usr/bin/env python
import sys
import os

# Take a sysroot directory and turn all the abolute symlinks and turn them into
# relative ones such that the sysroot is usable within another system.

if len(sys.argv) != 2:
    print("Usage is " + sys.argv[0] + "<directory>")
    sys.exit(1)

topdir = sys.argv[1]
topdir = os.path.abspath(topdir)

def handlelink(filep, subdir):
    link = os.readlink(filep)
    if link[0] != "/":
        return
    if link.startswith(topdir):
        return
    #print("Replacing %s with %s for %s" % (link, topdir+link, filep))
    print("Replacing %s with %s for %s" % (link, os.path.relpath(topdir+link, subdir), filep))
    os.unlink(filep)
    os.symlink(os.path.relpath(topdir+link, subdir), filep)

for subdir, dirs, files in os.walk(topdir):
    for f in files:
        filep = os.path.join(subdir, f)
        if os.path.islink(filep):
            #print("Considering %s" % filep)
            handlelink(filep, subdir)

Hello

I am looking to cross compile a relatively large code that is using the robotics cape library, and for which I use a makefile, and I want to do so using Windows WSL Ubuntu 20.04 LTS.

This seems to be relevant for doing so.

Could you point me in the right direction? I’ve found very vague information online, most of it suggesting I use Eclipse, whereas I’d rather have something where I can just use make. Also, I am completely unfamiliar with the “Linaro” tool…

Look forward to hearing back from you.

All the best!
Oscar

Hello @pr0scar, I’m attaching the document I created when I was setting up the toolchain on Windows. I used VSCode, MSYS2, CMake and another cross-compiler instead of WSL, but I think you can switch fairly easy.
Setting up VSCode on Windows.docx (149.1 КБ)

Hi there

Thank you for your response.

Any ideas how to use my makefile directly? I have everything exactly how I want in it.

I’m thinking this is a matter of installing the cross-compiler and then just setting up some flags with like -march or stuff like that…

Haven’t had the time to revise this, but will look to see if it can help.

Thanks a lot!

Oscar