invalid linker name in argument for target aarch64-apple-darwin (Mac OSX SDK 15.4) for dependencies that use CMAKE
Checklist
- I've looked through the issues and pull requests for similar reports
Describe your issue
I am trying to build a rust project that builds some cmake C++ project under the hood.
CMake is failing to configure:
CMake Error at /usr/local/share/cmake-3.23/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler
"/opt/osxcross/bin/aarch64-apple-darwin24.4-clang"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /target/aarch64-apple-darwin/debug/build/copper-showdown-emulator-sys-cf506242befcce52/out/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make -f Makefile cmTC_5138e/fast && /usr/bin/make -f CMakeFiles/cmTC_5138e.dir/build.make CMakeFiles/cmTC_5138e.dir/build
make[1]: Entering directory '/target/aarch64-apple-darwin/debug/build/copper-showdown-emulator-sys-cf506242befcce52/out/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_5138e.dir/testCCompiler.c.o
/opt/osxcross/bin/aarch64-apple-darwin24.4-clang -ffunction-sections -fdata-sections -fPIC --target=arm64-apple-macosx11.0 -stdlib=libc++ -fuse-ld=aarch64-apple-darwin24.4-ld -arch arm64 -mmacosx-version-min=11.0 -MD -MT CMakeFiles/cmTC_5138e.dir/testCCompiler.c.o -MF CMakeFiles/cmTC_5138e.dir/testCCompiler.c.o.d -o CMakeFiles/cmTC_5138e.dir/testCCompiler.c.o -c /target/aarch64-apple-darwin/debug/build/copper-showdown-emulator-sys-cf506242befcce52/out/build/CMakeFiles/CMakeTmp/testCCompiler.c
clang: warning: argument unused during compilation: '-fuse-ld=aarch64-apple-darwin24.4-ld' [-Wunused-command-line-argument]
Linking C executable cmTC_5138e
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/cmTC_5138e.dir/link.txt --verbose=1
/opt/osxcross/bin/aarch64-apple-darwin24.4-clang -ffunction-sections -fdata-sections -fPIC --target=arm64-apple-macosx11.0 -stdlib=libc++ -fuse-ld=aarch64-apple-darwin24.4-ld -arch arm64 -mmacosx-version-min=11.0 -Wl,-headerpad_max_install_names CMakeFiles/cmTC_5138e.dir/testCCompiler.c.o -o cmTC_5138e
clang: error: invalid linker name in argument '-fuse-ld=aarch64-apple-darwin24.4-ld'after diving a bit into it I managed to "fix" it (though I guess this is not a general fix). here is the root problem:
docker run --rm -it ghcr.io/cross-rs/aarch64-apple-darwin-cross:local bash
root@e60753e6e02e:/# echo "" > test.o
root@e60753e6e02e:/# /opt/osxcross/bin/aarch64-apple-darwin24.4-clang --target=arm64-apple-macosx11.0 -stdlib=libc++ -fuse-ld=aarch64-apple-darwin24.4-ld -arch arm64 -mmacosx-version-min=11.0 -Wl,-headerpad_m
ax_install_names test.o -o test
clang: error: invalid linker name in argument '-fuse-ld=aarch64-apple-darwin24.4-ld'
root@e60753e6e02e:/# /opt/osxcross/bin/aarch64-apple-darwin24.4-clang --target=arm64-apple-macosx11.0 -stdlib=libc++ -fuse-ld=/opt/osxcross/bin/aarch64-apple-darwin24.4-ld -arch arm64 -mmacosx-version-min=11.
0 -Wl,-headerpad_max_install_names test.o -o test
ld: file too small (length=1) file 'test.o' for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
root@e60753e6e02e:/# /opt/osxcross/bin/aarch64-apple-darwin24.4-clang --version
Ubuntu clang version 16.0.6 (++20231112100455+7cbf1a259152-1~exp1~20231112100542.106)
Target: arm64-apple-darwin24.4
Thread model: posix
InstalledDir: /usr/bin
root@e60753e6e02e:/# which aarch64-apple-darwin24.4-ld
/opt/osxcross/bin/aarch64-apple-darwin24.4-ldit seems (at least this version of clang?) needs an absolute path. it still cannot link in the above example because it is an empty test file. but the error is gone and it at least tries to link.
unfortunately it is not possible (or I don't see it?) to easily override this because the underlying environment variable is hardcoded in darwin-entry.sh and overriding it from Cross.toml didn't work.
So I created a simple derived container and changed the script to:
declare -x CFLAGS_${envvar_suffix}="-stdlib=libc++ -fuse-ld=/opt/osxcross/bin/aarch64-apple-darwin24.4-ld"
declare -x CXXFLAGS_${envvar_suffix}="-stdlib=libc++ -fuse-ld=/opt/osxcross/bin/aarch64-apple-darwin24.4-ld"that works for me for the moment (and my project compiles) but doesn't seem like a real solution?
What target(s) are you cross-compiling for?
aarch64-apple-darwin
Which operating system is the host (e.g computer cross is on) running?
- macOS
- Windows
- Linux / BSD
- other OS (specify in description)
What architecture is the host?
- x86_64 / AMD64
- arm32
- arm64 (including Mac M1)
What container engine is cross using?
- docker
- podman
- other container engine (specify in description)
cross version
cross 0.2.5 (1d07d3f 2026-07-15)
Example
No response
Additional information / notes
No response
Source: cross-rs/cross