Install Arm-Linux-Gnueabi For Mac10/21/2021
A cross-compile toolchain enables to compile code for a different hardware architecture than the development system. Download the latest version of the GNU Arm Embedded toolchain for macOS Double click on the downloaded.Published on Februin Rust Cross compiling Rust on Mac OS for an ARM Linux routerHere's how to create your own, shiny ARM gcc cross-compile toolchain for your Mac. Install the optional xcode command line tools install homebrew install the homebrew build tools 4.1 brew install crosstool-ng mpfr gmp grep 4.2 brew tap homebrew/dupes create a case sensitive volume using 'disk utility' use this volume to build the tool chain itself 6.1 generate a base configuration (for me this is an arm cortex a8)If you do not have homebrew installed (advanced).So I ran “rustup target list” to list all the installable targets: aarch64-apple-ios(many more x86, mips, powerpc and x86_64 targets)That’s a lot of possible targets. I already have rustup which I’ve used to install Rust for Mac OS and keep it up-to-date, so that’s handy. For comparison, normal Linux on 64-bit ARM starts as a flat binary image.The guide suggests rustup can be used to install extra cross compilation targets. The top of that guide shows an example of installing the cross-compilation toolchain for ARM on Ubuntu, but it required some work to adapt to Mac OS High Sierra, my desktop environment.So when Apple decided to allow installing custom kernels on the Macs with M1. The router is a Netgear R7000 with an ARM processor, running FreshTomato, a distribution of Linux for ARM and MIPS architecture consumer routers. Since the ARM architecture is omnipresent these days in UAVWanting to compile a small program I’d written in Rust to run on my home router, I found this guide to cross compilation of Rust code.
Arm-Linux-Gnueabi Install Homebrew Install![]() So we need to install a C toolchain targeting ARM.My first stop when looking to install open source tools on Mac OS is Homebrew, and indeed there’s a formula on there for arm-linux-gnueabihf-binutils – it looks like that could be what we need to get a linker targeting ARM Linux. Reading the guide seems to suggest that Rust doesn’t have its own linker for Linux targets – it uses the linker from a C toolchain, for example the GNU C compiler. So, it looks like we need a linker for ARM. Clang is the native C compiler for Mac OS, but I expect it can’t link an ARM executable in the way Rust wants. I installed the armv7-unknown-linux-gnueabihf target with: rustup target add armv7-unknown-linux-gnueabihfOK, let’s try compiling a “hello world” Rust application with that target: cargo build -target=armv7-unknown-linux-gnueabihfThat failed with a message “error: linking with cc failed: exit code: 1” and then a note showing the entire cc command, and a note saying: = note: clang: warning: argument unused during compilation: '-pie' Clang: error: linker command failed with exit code 1 (use -v to see invocation)OK, so I guess this is clang giving that error. Alternatives to microsoft office for businesses macThose look like parts of the GNU C library and other system libraries for Linux, which the Homebrew package arm-linux-gnueabihf-binutils doesn’t seem to include. Well, let’s try that instead, so the config is: OK, let’s try compiling again… Compiling rust-sandbox v0.1.0 (/Users/hugh/Source/rust-sandbox)Error: linking with `arm-linux-gnueabihf-ld` failed: exit code: 1= note: arm-linux-gnueabihf-ld: cannot find -ldlArm-linux-gnueabihf-ld: cannot find -lpthreadArm-linux-gnueabihf-ld: cannot find -lgcc_sArm-linux-gnueabihf-ld: cannot find -lutilThis is more promising, but it looks like the linker can’t find all of those libraries to link with. I know from the guide that this needs to go in ~/.cargo/config in a section like this: But the Homebrew formula didn’t install arm-linux-gnueabihf-gcc – it only has arm-linux-gnueabihf-ld. I know the linker is normally invoked as “ld”, and cross-compilation toolchains by convention prefix their tool names with the target name, so the ARM Linux linker should be arm-linux-gnueabihf-ld. This sounds promising as it removes the need to link against libpthread, etc, which we had problems with earlier.Let’s put the same linker configuration in ~/.cargo/config for the armv7-unknown-linux-musleabihf target: And try compiling our Rust program with this target: cargo build -target=armv7-unknown-linux-musleabihfCompiling rust-sandbox v0.1.0 (/Users/hugh/Source/rust-sandbox)Finished dev target(s) in 1.12sIt built, so let’s copy the executable to the router: scp target/armv7-unknown-linux-musleabihf/debug/rust-sandbox router:/tmp/And then SSH on to the router and run it: $ ssh router.sigmaris.infoGreat, it works! Using the musl C library and statically linking everything is somewhat less optimal than linking against the C library that’s already installed on Linux, as it means the built executable size is larger, but it’s good enough for a simple Rust program. The “musl” in the name refers to the musl C library, a small C library that can be statically linked with Rust programs instead of the GNU C library.
0 Comments
Leave a Reply.AuthorAnnette ArchivesCategories |