🌐
Reddit
reddit.com › r/macosprogramming › best way to cross compile for linux arm on mac
r/macosprogramming on Reddit: Best way to cross compile for Linux ARM on Mac
December 13, 2023 -

Hi,

I have been writing a CPP application that uses cmake that is mainly designed to run on Linux ARM but can be run on anything (including Mac) as it has hardware abstraction layers.

To date I develop on Mac and can build and run the application and unit tests on Mac. But when I want to build it for Linux ARM I move over to my old cheap windows laptop and use WSL to build it for ARM. This is painful and the laptop is very slow.

What is the best (lightweight) way to build for Linux ARM on Mac? I have a 2016 MacBook Pro that uses an Intel chip.

I have looked into the ARM toolchains here: https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads

But they are only suitable for bare metal targets, my OrangePi runs Linux so I don't think that is suitable.

I had thought of docker, so I could have a Linux container to do it, but its a pretty big install these days and having to run a VM in the background just seems excessive for wanting to do the odd build, but maybe there is no other better alternative.

Thanks!

🌐
UAV Lab @ Sydney
uav-lab.org › home
How to set up an ARM cross-compiler toolchain for macOS – UAV Lab @ Sydney
December 20, 2022 - A cross-compile toolchain enables to compile code for a different hardware architecture than the development system. We will be using the Intel/macOS to generate ARM/Linux (Cortex-Axx CPUs) or ARM/bare-metal (Cortex-Mxx Microcontrollers) code.
Discussions

Cross compiling to non-ARM targets - Apple Community
Is there any way I can compile it myself for the M1 chip in my iMac, or is this something that only the plug-in developer can do? 973 4 ... Not entirely sure where you’re headed, as you’re maybe looking for both cross-architecture and cross OS? The Apple tooling cross-builds to Apple targets (Arm and x86-64) just fine from macOS ... More on discussions.apple.com
🌐 discussions.apple.com
Cross-compiling from macOS to ARM
Trying to cross-compile from Mac to a raspberry pi zero W which runs ARMv6. Edit: Now the compiling issue is with openssl. If anyone knows how to get compiling openssl working, that'd be awesome. Original: I've set up my .cargo/config as the following [target.arm-unknown-linux-musleabihf] linker ... More on users.rust-lang.org
🌐 users.rust-lang.org
0
1
February 24, 2021
c - Build Apple Silicon binary on Intel machine - Stack Overflow
I don't have an Arm Mac in front of me, so I'm assuming this works. ... Sign up to request clarification or add additional context in comments. ... You probably don't have to. Clang is the default compiler and g++ command line is really just a shim that forwards to clang. More on stackoverflow.com
🌐 stackoverflow.com
How to cross compile for Apple M1 host on linux x86_64 build machine?
Just from a cursory google search, it's ARMv8. You might be able to just download a corresponding triplet toolchain (ex. gcc-armhf-linux-gnueabi) and add it to a toolchain file in cmake/bazel/etc. More on reddit.com
🌐 r/cpp_questions
2
29
January 22, 2021
🌐
DEV Community
dev.to › lewuathe › how-to-achieve-arm-cross-compilation-on-macos-3b08
How to achieve ARM cross-compilation on macOS - DEV Community
June 24, 2020 - $ brew tap ArmMbed/homebrew-formulae $ brew install arm-none-eabi-gcc · You should be able to find the compiler eventually. The following tools are installed in the local machine.
🌐
Apple Community
discussions.apple.com › thread › 254868190
Cross compiling to non-ARM targets - Apple Community
973 4 ... Not entirely sure where you’re headed, as you’re maybe looking for both cross-architecture and cross OS? The Apple tooling cross-builds to Apple targets (Arm and x86-64) just fine from macOS on Apple silicon, with either Xcode or the command-line tools installed.
🌐
GitHub
github.com › tpoechtrager › osxcross
GitHub - tpoechtrager/osxcross: MacOS Cross-Toolchain for Linux and *BSD · GitHub
xcrun g++ -arch x86_64 test.cpp -O3 -o test.x86_64 xcrun g++ -arch arm64 test.cpp -O3 -o test.arm64 xcrun lipo -create test.x86_64 test.arm64 -output test ... During the build: OSX_VERSION_MIN=XX.X ./build.sh. By passing -mmacos-version-min=XX.X to the compiler. By setting MACOSX_DEPLOYMENT_TARGET=XX.X env var. Note: Deployment target ≥ 10.9 defaults to libc++. Can be explicitely overriden by setting the C++ library to libstdc++ via -stdlib=libstdc++. multiarch/crossbuild: various cross-compilers (Systems: Linux, macOS, Windows, Archs: x86_64,i386, arm, ppc, mips) in Docker.
Starred by 3.3K users
Forked by 356 users
Languages   C++ 45.4% | Shell 39.2% | C 14.1%
🌐
Rust Programming Language
users.rust-lang.org › help
Cross-compiling from macOS to ARM - help - The Rust Programming Language Forum
February 24, 2021 - Trying to cross-compile from Mac to a raspberry pi zero W which runs ARMv6. Edit: Now the compiling issue is with openssl. If anyone knows how to get compiling openssl working, that'd be awesome. Original: I've set up my .cargo/config as the following [target.arm-unknown-linux-musleabihf] linker ...
Top answer
1 of 3
15

I found a hint on this page to use this:

-target arm64-apple-macos11

When I run this from my mac:

clang++ main.cpp -target arm64-apple-macos11

The resulting a.out binary is listed as:

% file a.out
a.out: Mach-O 64-bit executable arm64

I have XCode 12.2 installed.

I don't have an Arm Mac in front of me, so I'm assuming this works.

2 of 3
6

We ended up solving solving this and being able to compile darwin-arm64 and debian-aarch64 binaries on GitHub Actions' x86-64 machines.

We pre-compiled all our dependencies for arm64 and linked them statically as well as dynamically.

export RELAY_DEPS_PATH=./build-deps/arm64
export PKG_CONFIG_PATH=./build-deps/arm64/lib/pkgconfig

cd ./relay-deps
TARGET=./build-deps make install

cd ./relay
phpize
./configure CFLAGS='-target arm64-apple-macos' \
  --host=aarch64-apple-darwin \
  --enable-relay-jemalloc-prefix
  [snip...]

make

# Dynamically linked binary
cc --target=arm64-apple-darwin \
  ${wl}-flat_namespace ${wl}-undefined ${wl}suppress \
  -o .libs/relay.so -bundle .libs/*.o \
  -L$RELAY_DEPS_PATH/lib -lhiredis -ljemalloc_pic [snip...]

# re-link to standard paths
./relay-deps/utils/macos/relink.sh .libs/relay.so /usr/local/lib
cp .libs/relay.so modules/relay.so

# Build a statically linked shared object
cc --target=arm64-apple-darwin \
  ${wl}-flat_namespace ${wl}-undefined ${wl}suppress \
  -o .libs/relay-static.so -bundle .libs/*.o \
  $RELAY_DEPS_PATH/lib/libhiredis.a \
  $RELAY_DEPS_PATH/lib/libjemalloc_pic.a \
  [snip...]

The relink.sh:

#!/bin/bash
set -e

printUsage() {
    echo "$0 <shared-object> <prefix>"
    exit 1
}

if [[ ! -f "$1" || -z "$2" ]]; then
    printUsage
    exit 1
fi

INFILE=$1
PREFIX=$2

links=(libjemalloc libhiredis [snip...])

if [ -z "$PREFIX" ]; then
    PREFIX=libs
fi

for link in ${links[@]}; do
    FROM=$(otool -L "$INFILE"|grep $link|awk '{print $1}')
    FILE=$(basename -- "$FROM")
    TO="$PREFIX/$FILE"

    echo "$FROM -> $TO"
    install_name_tool -change "$FROM" "$TO" "$1"
done
Find elsewhere
🌐
Reddit
reddit.com › r/cpp_questions › how to cross compile for apple m1 host on linux x86_64 build machine?
r/cpp_questions on Reddit: How to cross compile for Apple M1 host on linux x86_64 build machine?
January 22, 2021 -

I have an x86_64 device running Ubuntu 18.04. How would I go about cross compiling for MacOS M1 chip?

Would I need to build in a MacOS docker image with an aarch64 clang toolchain?

Any guidance would be appreciated. Most of what I see online is how to compile native for M1, but not much on cross compiling.

As an extension, how would I compile for the M1 chip on a x86_64 mac? Would I just need to install the aarch64 clang toolchain and use that?

🌐
GitHub
gist.github.com › disposedtrolley › 06d37e1db82b80ccf8c5d801eaa29373
Installing the GNU ARM Embedded Toolchain for macOS · GitHub
The ARM Embedded Toolchain is a GNU licensed cross compiler for ARM CPU architectures, allowing you to compile C/C++ code into binaries which can execute on CPUs such as the Cortex-M line of microcontrollers.
🌐
Google Groups
groups.google.com › g › bazel-discuss › c › eAcrir-HYdA
Building (or Cross-compiling) for macos arm64 (Apple M1 chip)
I have gcc11 for arm installed on the apple M1 system · $ which gcc-11 /opt/homebrew/bin/gcc-11 $ file /opt/homebrew/bin/gcc-11 /opt/homebrew/bin/gcc-11: Mach-O 64-bit executable arm64
🌐
Stack Overflow
stackoverflow.com › questions › 74476351 › cross-compiling-for-x64-on-arm-apple-silicon
c - Cross Compiling for x64 on ARM (Apple Silicon) - Stack Overflow
It is definitely possible to target Intel when compiling on an Apple Silicon (ARM64) system, as Xcode does that all the time when building universal bundles of an app. However, I am unable to repli...
🌐
Cycling '74
cycling74.com › forums › cross-compiling-for-m1
Cross compiling for M1? - Dev Forum | Cycling '74
I realize I will need to test the binary on another machine, but right now that is somewhat doable for me while developing on M1 is not. thanks! ... you can cross compile for arm64, or make Fat binaries, from an Intel Mac with Xcode 12 and up (not sure what minor version needed, maybe .3 or .4).
🌐
CodeJam
codejam.info › 2026 › 04 › cross-compiling-tauri-linux-arm-mac.html
Cross-compiling a Tauri app for x86-64 Linux from an ARM Mac (no emulation ⚡️) | CodeJam
I got distracted. 😂 ... Use macOS Virtualization framework to run a ARM Linux VM at near-native performance. Inside that VM, configure Linux to cross-compile the app for x86-64.
🌐
GitHub
github.com › qbittorrent › qBittorrent › wiki › Compilation-macOS-(x86_64,-arm64,-cross-compilation)
Compilation macOS (x86_64, arm64, cross compilation)
You switched accounts on another tab or window. Reload to refresh your session. ... There was an error while loading. Please reload this page. ... This guide covers qBittorrent compilation process for any supported Mac systems as of writing, i.e. following this guide you will be able to build as x86_64 (aka for Intel chip based Mac) so as arm64 (aka for Apple Silicon based Mac) binaries. Cross...
Author   qbittorrent
🌐
Stack Overflow
stackoverflow.com › questions › 26395127 › cross-compile-source-code-for-arm-based-linux-system-on-mac-issue
macos - Cross Compile source code for ARM based Linux system on Mac issue - Stack Overflow
port install arm-none-eabi-gcc port install arm-none-eabi-binutils i downloaded the arm tools on my mac. export CCPREFIX=/opt/local/bin/arm-none-eabi- make ARCH=arm CROSS_COMPILE=${CCPREFIX} how...
🌐
Sigmaris
sigmaris.info › blog › 2019 › 02 › cross-compiling-rust-on-mac-os-for-an-arm-linux-router
Cross compiling Rust on Mac OS for an ARM Linux router - sigmaris.info
February 4, 2019 - 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. So let’s install that with: ... That installs a set of tools named arm-linux-gnueabihf-addr2line, arm-linux-gnueabihf-ar and so on. 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.
🌐
GitHub
github.com › conan-io › conan › issues › 16585
Cross compiling macos x86_64 library on macos arm64 - what is best practice · Issue #16585 · conan-io/conan
July 1, 2024 - What is your question? Hi! I'm using the latest macos arm64 images on github actions and we are still supporting x86_64. Therefore cross-compiling from arm to the x86_64 target. Am I correct in thinking that the recommended way to cross-...
Author   bldrvnlw