.. ot-topic:: linux.toolchain.cross.basics :dependencies: linux.toolchain.basics .. include:: Cross Development ================= .. contents:: :local: Native Compilation ------------------ * Compiler runs on a machine, say ``x86_64`` * Produces code *for that machine* * Uses header files and libraries from that machine * Default *paths* for headers and libraries * ``/usr/include``: e.g. ``#include `` is found as ``/usr/include/stdio.h`` * ``/usr/lib``, ``/lib64``, ...: e.g. ``-lpthread`` ("linker, please go find me the ``pthread`` library") is resolved to ``/lib64/libpthread.so`` Cross? ------ .. sidebar:: **See also** * :doc:`/blog/2022/09/cross-raspi` * :doc:`/trainings/material/soup/linux/toolchain/raspberry-pi/toolchain-build-docker-fedora` * Compiler runs on *host* machine (e.g. ``x86_64``) * Produces code for the *target* machine (e.g. ``armv7l``) **Simple?** |longrightarrow| No * Code must be built against *target situation* * Header files and libraries * |longrightarrow| must be available on *host* * |longrightarrow| ``sysroot`` * Must match the target situation |longrightarrow| binary compatibility * Statically linked cross build generally ok * *But:* shared libraries are a continuous source of pain **Challenges** * Cross compiler: finding or building one that works * Trial and error, mostly * Building one: `crosstool-ng `__ * Using a metadistribution like `Yocto `__: give you a cross toolchain as by-product of creating the *target rootfilesystem* * ``sysroot`` * Target root filesystem, in principle * Ideally stripped down to a miniumum * Don't need target *executables* on the host, for example (they won't run) * Ideally a by-product of root filesystem creation The ``sysroot`` --------------- .. sidebar:: **Topics** * :doc:`sshfs <../../ssh/sshfs>` * The situation on the target, made available on the host * Usually a single tree, containing a subset of the target's *root filesystem* .. code-block:: console :caption: One of a number of sysroots; on the *host* $ ls -l ~/cross/sysroots/raspberry/ total 0 drwxrwxr-x. 1 jfasch jfasch 38 Mar 29 19:00 lib drwxrwxr-x. 1 jfasch jfasch 20 Mar 29 18:59 usr * Easy solution: use :doc:`sshfs <../../ssh/sshfs>` to mount the target root directory (that does not scale up to reality though)