Cross Compiler Toolchain
Table of contents
- Cross Compiler Toolchain
- Table of contents
- Setup the workspace
- Toolchain naming convention and folder structure
- Add new toolchain
- Run Device Software Binaries built with toolchain
Setup the workspace
brazil ws create --root IotManagedIntegrationsToolchaincd IotManagedIntegrationsToolchainbrazil ws use -p IotManagedIntegrationsToolchainCommon -p IoTSmartHomeDeviceSoftwareCommonDependencies- Checkout your toolchain package, E.g
brazil ws use -p IotManagedIntegrationsToolchain-x86_64-unknown-linux-gnu
Toolchain naming convention and folder structure
toolchain's name and folder path shall be:
/tmp/x-tools/<host-arch>__<target-arch>
├── <target-arch>
├── bin
├── build.log.bz2
├── cross_file.txt # cross compile config of meson
├── env.sh # env variables to use this toolchain
├── include
├── lib
├── libexec
└── share
Add new toolchain
Install and config crosstool-ng
- Clone
https://github.com/crosstool-ng/crosstool-ngin some other location - Cd into the repo to install it:
- Run
./bootstrap - Run
./configure --enable-local - Run
make - Refer more details: https://crosstool-ng.github.io/docs/install/
- Configure crosstool-ng by:
- Run
./ct-ng menuconfigto configure the install path, target arch, kernel version, glibc and so on. - Check your config:
./ct-ng show-config - Refer more details: https://crosstool-ng.github.io/docs/configuration/
- Build the toolchain:
- Run
./ct-ng build, it shall install toolchain at~/x-tools/<toolchain-name>- You might have build error during build, check build.log for details, most common issue is that you are missing some dependencies
- You might need to hardcode the python path in the config file if running on al2 cloud desktop
- You might need to change ownership/permission of generated toolchain:
sudo chown -R <your username>:<your groupname> <path to toolchain>chmod -R u+rw <path to toolchain>- Create the env file for your toolchain, it shall name as
env.sh, save it at the top level folder of your toolchain. - Create the cross_file.txt for your toolchain, it shall name as
cross_file.txt, save it at the top level folder of your toolchain. - cross_file.txt can't read any env variable, so you need to absolute path for each property in it.
Install libraries into toolchain
source <path to your env.sh>- run
./install_dependency.sh
Run Device Software Binaries built with toolchain
The binary built with toolchain are supposed to run within the toolchain env, the env.sh has already setup LDFLAGS to set rpath for binary at compile time for x86_64 toolchain.
You should be able to run the binary directly in your host.
If more modification needed, you can use patchelf tool to set the ld and library path for your binary:
- Install patchelf if not yet by
sudo yum install patchelf - Patch your binary by
patchelf --set-interpreter $SYSROOT_PATH/lib/ld-<your ld version>.so --add-rpath $SYSROOT_PATH/lib:$SYSROOT_PATH/usr/lib:$SYSROOT_PATH/usr/local/lib <path to your binary>
Or you can set env var to temporary overwrite lib path for your binary
export LD_LIBRARY_PATH=$SYSROOT_PATH/lib:$SYSROOT_PATH/usr/lib:$SYSROOT_PATH/usr/local/lib- This approach will affect all binary in your session, if you see segment fault for your commands, unset the env var by
unset LD_LIBRARY_PATH