#651·clay

Odin bindings: The script build-clay-lib.sh gives an error on macOS (with solution)

Author: flevin58Created Aug 25, 2026Updated Aug 25, 2026

When compiling in my Mac M1 mini the script shows the following error:

» ./build-clay-lib.sh 
ar: creating archive clay-odin/macOS/clay.a
ar: creating archive clay-odin/macos-arm64/clay.a
ar: creating archive clay-odin/linux/clay.a
ranlib: warning: archive member 'clay.o' not a mach-o file
error: unable to create target: 'No available targets are compatible with triple "wasm32"'
1 error generated.

I found the problem: macOS is using by default /usr/bin/clang and /usr/bin/ar which are not compatible and cannot be changed by the user because they are needed by the operating system. The correct way is to add environment vars $CC and $AR that point to the correct versions. In my case I am using this setting in my .zshrc file:

bash
LLVM_BIN=/opt/homebrew/Cellar/llvm@22/22.1.8/bin
export AR=${LLVM_BIN}/llvm-ar
export CC=${LLVM_BIN}/clang

I locally modified the sript substituting the following:

clang with ${CC:-clang} ar with ${AR:-ar}

This solution is much better because it defaults as it is now, but allows the developer to override as I did.

Here the modified script, that works ok:

cp ../../clay.h clay.c; # Intel Mac rm -f clay-odin/macos/clay.a && ${CC:-clang} -c -DCLAY_IMPLEMENTATION -o clay.o -ffreestanding -static -target x86_64-apple-darwin clay.c -fPIC -O3 && ${AR:-ar} r clay-odin/macos/clay.a clay.o; # ARM Mac rm -f clay-odin/macos-arm64/clay.a && ${CC:-clang} -c -DCLAY_IMPLEMENTATION -g -o clay.o -static clay.c -fPIC -O3 && ${AR:-ar} r clay-odin/macos-arm64/clay.a clay.o; # x64 Windows rm -f clay-odin/windows/clay.lib && ${CC:-clang} -c -DCLAY_IMPLEMENTATION -o clay-odin/windows/clay.lib -ffreestanding -target x86_64-pc-windows-msvc -fuse-ld=llvm-lib -static -O3 clay.c; # Linux rm -f clay-odin/linux/clay.a && ${CC:-clang} -c -DCLAY_IMPLEMENTATION -o clay.o -ffreestanding -static -target x86_64-unknown-linux-gnu clay.c -fPIC -O3 && ${AR:-ar} r clay-odin/linux/clay.a clay.o; # WASM rm -f clay-odin/wasm/clay.o && ${CC:-clang} -c -DCLAY_IMPLEMENTATION -o clay-odin/wasm/clay.o -target wasm32 -nostdlib -static -O3 clay.c; rm clay.o; rm clay.c;