Buildroot-ts Cross Compiler: Difference between revisions
(Initial commit) |
(Add note on exporting PATH) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Buildroot | In order to generate a cross-compiler from Buildroot, first configure the target build as outlined in [[#Buildroot - Building|the first steps of the build instructions]]. Once configured, a separate <source inline>make</source> command can be issued to generate a tarball package of the cross-compiler. This can be unpacked to any location on the host Linux workstation's filesystem and then used to cross-compile additional applications for the target. The build, setup, and use of the cross-compiler can be done with the following steps: | ||
<source lang=bash> | |||
# Be sure the target is configured first! | |||
# The following command will output the cross-compiler package as well as build the target image completely if not built already | |||
make sdk | |||
# Unpack the tarball to new directory in the users home directory | |||
# Note that the tarball name may be slightly different depending on how the toolchain is configured in Buildroot | |||
mkdir ~/buildroot-toolchain | |||
tar xf buildroot/output/images/arm-buildroot-linux-gnueabihf_sdk-buildroot.tar.gz -C ~/buildroot-toolchain/ | |||
See the [https://buildroot.org/downloads/manual/manual.html#build-toolchain-with-buildroot Buildroot | # Update the path information for the toolchain (must be done when the tarball is unpacked, or if the root folder of the toolchain is moved!) | ||
# Note that, as above, the path for the compiler may be slightly different depending on how the toolchain is configured in Buildroot | |||
~/buildroot-toolchain/arm-buildroot-linux-gnueabihf_sdk-buildroot/relocate-sdk.sh | |||
# Create a simple Hello World application source | |||
cat << EOF > hello.c | |||
#include <stdio.h> | |||
void main(void) { printf("Hello!\n"); } | |||
EOF | |||
# Build a binary from the Hello World source that can be run on the target device | |||
~/buildroot-toolchain/arm-buildroot-linux-gnueabihf_sdk-buildroot/bin/arm-linux-gcc hello.c -o hello | |||
# This cross compiler can be added to the user's PATH variable for easy access | |||
export PATH=$PATH:~/buildroot-toolchain/arm-buildroot-linux-gnueabihf_sdk-buildroot/bin | |||
arm-linux-gcc hello.c -o hello | |||
</source> | |||
The <source inline>hello</source> binary can then be copied to the target device and executed on it. | |||
Note that the <source inline>make sdk</source> command can be run at any time to generate the toolchain tarball. Even after Buildroot has generated the output image. | |||
Buildroot is extremely flexible in its generation and use of a cross-compiler. See the Buildroot manual for more information on [https://buildroot.org/downloads/manual/manual.html#_advanced_usage advanced use of the Buildroot generated toolchain] as well as [https://buildroot.org/downloads/manual/manual.html#build-toolchain-with-buildroot using Buildroot's generated cross-compiler as an external compiler for Buildroot]. |
Latest revision as of 18:14, 24 April 2023
In order to generate a cross-compiler from Buildroot, first configure the target build as outlined in the first steps of the build instructions. Once configured, a separate make
command can be issued to generate a tarball package of the cross-compiler. This can be unpacked to any location on the host Linux workstation's filesystem and then used to cross-compile additional applications for the target. The build, setup, and use of the cross-compiler can be done with the following steps:
# Be sure the target is configured first!
# The following command will output the cross-compiler package as well as build the target image completely if not built already
make sdk
# Unpack the tarball to new directory in the users home directory
# Note that the tarball name may be slightly different depending on how the toolchain is configured in Buildroot
mkdir ~/buildroot-toolchain
tar xf buildroot/output/images/arm-buildroot-linux-gnueabihf_sdk-buildroot.tar.gz -C ~/buildroot-toolchain/
# Update the path information for the toolchain (must be done when the tarball is unpacked, or if the root folder of the toolchain is moved!)
# Note that, as above, the path for the compiler may be slightly different depending on how the toolchain is configured in Buildroot
~/buildroot-toolchain/arm-buildroot-linux-gnueabihf_sdk-buildroot/relocate-sdk.sh
# Create a simple Hello World application source
cat << EOF > hello.c
#include <stdio.h>
void main(void) { printf("Hello!\n"); }
EOF
# Build a binary from the Hello World source that can be run on the target device
~/buildroot-toolchain/arm-buildroot-linux-gnueabihf_sdk-buildroot/bin/arm-linux-gcc hello.c -o hello
# This cross compiler can be added to the user's PATH variable for easy access
export PATH=$PATH:~/buildroot-toolchain/arm-buildroot-linux-gnueabihf_sdk-buildroot/bin
arm-linux-gcc hello.c -o hello
The hello
binary can then be copied to the target device and executed on it.
Note that the make sdk
command can be run at any time to generate the toolchain tarball. Even after Buildroot has generated the output image.
Buildroot is extremely flexible in its generation and use of a cross-compiler. See the Buildroot manual for more information on advanced use of the Buildroot generated toolchain as well as using Buildroot's generated cross-compiler as an external compiler for Buildroot.