gcccross-compilingyoctotoolchainsysroot

Meaning of --sysroot=$SDKTARGETSYSROOT?


I have something very puzzling (or sound strange to me). I wish to have some clearer explanation from you guys.

Have been cross compiling a file using environmental-setup-file (environment-setup-aarch64-poky-linux) from a Yocto Distribution for an arm machine. I understand it is to set environment (by using source environment-setup-file).

It contains

What I find confusing is that the location of toolchain. Isn't it supposed to be found in SDKTARGETSYSROOT (The toolchain is set by others, SDKTARGETSYSROOT= /opt/fsl-imx-xwayland/4.14-sumo/environment-setup-aarch64-poky-linux) ? I find my aarch64-poky-linux-gcc to be found in directory outside of that SDKTARGETSYSROOT (though the gcc is found in PATH, /opt/fsl-imx-xwayland/4.14-sumo/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux)

Is there a rationale for doing it this way? I have been coding the code but would like to learn why this is so?

Thanks


Solution

  • This has got to do more with the cross canadian compiler (GCC in this case) rather than Yocto, the Yocto Project wires its compiler logic using the --sysroot argument passed to GCC: https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html

    This tells GCC to treat whats passed as --sysroot as if it was the sysroot on a typical compilation on target, e.g. usually GCC expects to find headers in /usr/include or libraries in /usr/lib , if we pass --sysroot=/foo/ then it will automatically look at /foo/usr/include and /foo/usr/lib respectively.

    The toolchain scripts in the Yocto Project use --sysroot=SDKTARGETSYSROOT to pass the directory where the SDK is installed, hence it finds the proper header and libs to be able to cross compile from the SDK, for more info: https://git.yoctoproject.org/poky/tree/meta/classes/toolchain-scripts.bbclass

    Now why is GCC outside that directory?, because that directory only contains files for the target architecture (hence SDKTARGETSYSROOT, SDK: for the SDK, TARGET: meant for the target arch, SYSROOT: the sysroot to be used), and GCC is not. GCC is compiled to run in your HOST, hence it doesnt belong in that directory, it is precisely why you see the x86_64-pokysdk-linux part of the path where GCC is actually installed in, your HOST triplet is a 64 bit x86 architecture, an SDK built by poky (Yocto), and its OS is Linux.