Cross-compiling from Linux to macOS (Zig/osxcross): impossible ? #4267
|
Hi!
I've tried both Zig and osxcross, and in both cases I eventually run into very similar issues — typically related to missing macOS system libraries like objc or resolv. zigHere’s an example using Zig: CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 \
CC="zig cc -target aarch64-macos --sysroot /usr/local/SDK/MacOSX14.sdk" \
CXX="zig c++ -target aarch64-macos --sysroot /usr/local/SDK/MacOSX14.sdk" \
CGO_CFLAGS="-isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -isystem /usr/local/SDK/MacOSX14.sdk/usr/include" \
CGO_CXXFLAGS="-isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -isystem /usr/local/SDK/MacOSX14.sdk/usr/include" \
CGO_LDFLAGS="-mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -framework Foundation -framework UniformTypeIdentifiers -framework IOKit -framework CoreFoundation -framework Security -framework Cocoa -framework WebKit -framework AppKit -lobjc" \
go build -tags=production \
-ldflags="-linkmode=external" \
-o /tmp/tuna-desktop-darwin-arm64 ./desktop
This results in the following error: /usr/local/go/pkg/tool/linux_amd64/link: running zig failed: exit status 1
/usr/local/bin/zig cc -target aarch64-macos --sysroot /usr/local/SDK/MacOSX14.sdk -arch arm64 -Wl,-headerpad,1144 -o $WORK/b001/exe/a.out /tmp/go-link-3902535930/go.o /tmp/go-link-3902535930/000000.o /tmp/go-link-3902535930/000001.o /tmp/go-link-3902535930/000002.o /tmp/go-link-3902535930/000003.o /tmp/go-link-3902535930/000004.o /tmp/go-link-3902535930/000005.o /tmp/go-link-3902535930/000006.o /tmp/go-link-3902535930/000007.o /tmp/go-link-3902535930/000008.o /tmp/go-link-3902535930/000009.o /tmp/go-link-3902535930/000010.o /tmp/go-link-3902535930/000011.o /tmp/go-link-3902535930/000012.o /tmp/go-link-3902535930/000013.o /tmp/go-link-3902535930/000014.o /tmp/go-link-3902535930/000015.o /tmp/go-link-3902535930/000016.o /tmp/go-link-3902535930/000017.o /tmp/go-link-3902535930/000018.o /tmp/go-link-3902535930/000019.o /tmp/go-link-3902535930/000020.o /tmp/go-link-3902535930/000021.o /tmp/go-link-3902535930/000022.o /tmp/go-link-3902535930/000023.o /tmp/go-link-3902535930/000024.o /tmp/go-link-3902535930/000025.o /tmp/go-link-3902535930/000026.o /tmp/go-link-3902535930/000027.o /tmp/go-link-3902535930/000028.o /tmp/go-link-3902535930/000029.o /tmp/go-link-3902535930/000030.o /tmp/go-link-3902535930/000031.o /tmp/go-link-3902535930/000032.o /tmp/go-link-3902535930/000033.o /tmp/go-link-3902535930/000034.o /tmp/go-link-3902535930/000035.o /tmp/go-link-3902535930/000036.o /tmp/go-link-3902535930/000037.o /tmp/go-link-3902535930/000038.o /tmp/go-link-3902535930/000039.o /tmp/go-link-3902535930/000040.o /tmp/go-link-3902535930/000041.o /tmp/go-link-3902535930/000042.o -mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -framework Foundation -framework UniformTypeIdentifiers -framework IOKit -framework CoreFoundation -framework Security -framework Cocoa -framework WebKit -framework AppKit -lobjc -framework IOKit -lresolv -mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -framework Foundation -framework UniformTypeIdentifiers -framework IOKit -framework CoreFoundation -framework Security -framework Cocoa -framework WebKit -framework AppKit -lobjc -mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -framework Foundation -framework UniformTypeIdentifiers -framework IOKit -framework CoreFoundation -framework Security -framework Cocoa -framework WebKit -framework AppKit -lobjc -framework CoreFoundation -framework CoreFoundation -framework Security -mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -framework Foundation -framework UniformTypeIdentifiers -framework IOKit -framework CoreFoundation -framework Security -framework Cocoa -framework WebKit -framework AppKit -lobjc -mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -framework Foundation -framework UniformTypeIdentifiers -framework IOKit -framework CoreFoundation -framework Security -framework Cocoa -framework WebKit -framework AppKit -lobjc -mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -framework Foundation -framework UniformTypeIdentifiers -framework IOKit -framework CoreFoundation -framework Security -framework Cocoa -framework WebKit -framework AppKit -lobjc -framework CoreFoundation -framework IOKit -mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -framework Foundation -framework UniformTypeIdentifiers -framework IOKit -framework CoreFoundation -framework Security -framework Cocoa -framework WebKit -framework AppKit -lobjc -framework Foundation -framework Cocoa -framework WebKit -framework Foundation -framework Cocoa -framework WebKit -framework Foundation -framework Cocoa -framework WebKit -framework Foundation -framework Cocoa -framework WebKit -framework Foundation -framework Cocoa -framework WebKit -framework Foundation -framework Cocoa -framework WebKit -framework AppKit -framework Foundation -framework Cocoa -framework Foundation -framework Cocoa -framework WebKit -lobjc -mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -framework Foundation -framework UniformTypeIdentifiers -framework IOKit -framework CoreFoundation -framework Security -framework Cocoa -framework WebKit -framework AppKit -lobjc -framework Foundation -framework WebKit -framework Foundation -framework WebKit
error: unable to find dynamic system library 'objc' using strategy 'paths_first'. searched paths: none
error: unable to find dynamic system library 'resolv' using strategy 'paths_first'. searched paths: none
error: unable to find dynamic system library 'objc' using strategy 'paths_first'. searched paths: none
error: unable to find dynamic system library 'objc' using strategy 'paths_first'. searched paths: none
error: unable to find dynamic system library 'objc' using strategy 'paths_first'. searched paths: none
error: unable to find dynamic system library 'objc' using strategy 'paths_first'. searched paths: none
error: unable to find dynamic system library 'objc' using strategy 'paths_first'. searched paths: none
error: unable to find dynamic system library 'objc' using strategy 'paths_first'. searched paths: none
error: unable to find dynamic system library 'objc' using strategy 'paths_first'. searched paths: none
error: unable to find dynamic system library 'objc' using strategy 'paths_first'. searched paths: none
osxcross (clang)Here’s an example using osxcross: CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 \
CC="oa64-clang --sysroot /usr/local/SDK/MacOSX14.sdk" \
CXX="oa64-clang++ --sysroot /usr/local/SDK/MacOSX14.sdk" \
CGO_CFLAGS="-mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -isystem /usr/local/SDK/MacOSX14.sdk/usr/include" \
CGO_CXXFLAGS="-mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -isystem /usr/local/SDK/MacOSX14.sdk/usr/include" \
CGO_LDFLAGS="-mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -framework Foundation -framework UniformTypeIdentifiers -framework IOKit -framework CoreFoundation -framework Security -framework Cocoa -framework WebKit -framework AppKit -lobjc" \
go build -x -v -tags=production \
-ldflags="-linkmode=external" \
-o /tmp/tuna-darwin-arm64 ./desktoperror: /usr/local/go/pkg/tool/linux_amd64/link: running oa64-clang failed: exit status 1
/usr/local/bin/oa64-clang --sysroot /usr/local/SDK/MacOSX14.sdk -arch arm64 -Wl,-headerpad,1144 -o $WORK/b001/exe/a.out -Qunused-arguments /tmp/go-link-2159890098/go.o /tmp/go-link-2159890098/000000.o /tmp/go-link-2159890098/000001.o /tmp/go-link-2159890098/000002.o /tmp/go-link-2159890098/000003.o /tmp/go-link-2159890098/000004.o /tmp/go-link-2159890098/000005.o /tmp/go-link-2159890098/000006.o /tmp/go-link-2159890098/000007.o /tmp/go-link-2159890098/000008.o /tmp/go-link-2159890098/000009.o /tmp/go-link-2159890098/000010.o /tmp/go-link-2159890098/000011.o /tmp/go-link-2159890098/000012.o /tmp/go-link-2159890098/000013.o /tmp/go-link-2159890098/000014.o /tmp/go-link-2159890098/000015.o /tmp/go-link-2159890098/000016.o /tmp/go-link-2159890098/000017.o /tmp/go-link-2159890098/000018.o /tmp/go-link-2159890098/000019.o /tmp/go-link-2159890098/000020.o /tmp/go-link-2159890098/000021.o /tmp/go-link-2159890098/000022.o /tmp/go-link-2159890098/000023.o /tmp/go-link-2159890098/000024.o /tmp/go-link-2159890098/000025.o /tmp/go-link-2159890098/000026.o /tmp/go-link-2159890098/000027.o /tmp/go-link-2159890098/000028.o /tmp/go-link-2159890098/000029.o /tmp/go-link-2159890098/000030.o /tmp/go-link-2159890098/000031.o /tmp/go-link-2159890098/000032.o /tmp/go-link-2159890098/000033.o /tmp/go-link-2159890098/000034.o /tmp/go-link-2159890098/000035.o /tmp/go-link-2159890098/000036.o /tmp/go-link-2159890098/000037.o /tmp/go-link-2159890098/000038.o /tmp/go-link-2159890098/000039.o /tmp/go-link-2159890098/000040.o /tmp/go-link-2159890098/000041.o /tmp/go-link-2159890098/000042.o -mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -framework Foundation -framework UniformTypeIdentifiers -framework IOKit -framework CoreFoundation -framework Security -framework Cocoa -framework WebKit -framework AppKit -lobjc -framework IOKit -lresolv -mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -framework Foundation -framework UniformTypeIdentifiers -framework IOKit -framework CoreFoundation -framework Security -framework Cocoa -framework WebKit -framework AppKit -lobjc -mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -framework Foundation -framework UniformTypeIdentifiers -framework IOKit -framework CoreFoundation -framework Security -framework Cocoa -framework WebKit -framework AppKit -lobjc -framework CoreFoundation -framework CoreFoundation -framework Security -mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -framework Foundation -framework UniformTypeIdentifiers -framework IOKit -framework CoreFoundation -framework Security -framework Cocoa -framework WebKit -framework AppKit -lobjc -mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -framework Foundation -framework UniformTypeIdentifiers -framework IOKit -framework CoreFoundation -framework Security -framework Cocoa -framework WebKit -framework AppKit -lobjc -mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -framework Foundation -framework UniformTypeIdentifiers -framework IOKit -framework CoreFoundation -framework Security -framework Cocoa -framework WebKit -framework AppKit -lobjc -framework CoreFoundation -framework IOKit -mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -framework Foundation -framework UniformTypeIdentifiers -framework IOKit -framework CoreFoundation -framework Security -framework Cocoa -framework WebKit -framework AppKit -lobjc -framework Foundation -framework Cocoa -framework WebKit -framework Foundation -framework Cocoa -framework WebKit -framework Foundation -framework Cocoa -framework WebKit -framework Foundation -framework Cocoa -framework WebKit -framework Foundation -framework Cocoa -framework WebKit -framework Foundation -framework Cocoa -framework WebKit -framework AppKit -framework Foundation -framework Cocoa -framework Foundation -framework Cocoa -framework WebKit -lobjc -mmacosx-version-min=11.0.0 -isysroot /usr/local/SDK/MacOSX14.sdk -F/usr/local/SDK/MacOSX14.sdk/System/Library/Frameworks -framework Foundation -framework UniformTypeIdentifiers -framework IOKit -framework CoreFoundation -framework Security -framework Cocoa -framework WebKit -framework AppKit -lobjc -framework Foundation -framework WebKit -framework Foundation -framework WebKit
Undefined symbols for architecture arm64:
"___isPlatformVersionAtLeast", referenced from:
-[WailsContext CreateWindow::::::::::::::::::::::::] in 000035.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)As far as I understand, Apple deliberately does not allow cross-compiling modern macOS GUI applications outside of their own tools. ___isPlatformVersionAtLeast is used in frameworks like AppKit, WebKit, and UniformTypeIdentifiers. So, we can cross-compile CLI software, but if it's something GUI-related — like Wails, for example — then it's impossible to do without a real macOS. Maybe it makes sense to use the old sdk 10.15 for example? |
Replies: 7 comments 10 replies
|
There's also the legal aspect too. You'd need to have a mac anyway to be allowed to use the SDKs... |
|
You don't need a Mac to download the SDK. |
|
if you know the type signatures of the functions you need to call, the symbol names and where the location of the library will be on MacOS, then it's possible to create |
|
I'm glad I'm not the only one who is having these issues with webview as bad as this is to say. On the plus side I did find out that zig flags can be much less complicated before running into the missing objc and resolv problem. Mac min version can be specified on the target and isysroot, iwithsysroot, iframeworkwithsysroot for including the SDK plus local system libraries. Here are my docker files for cross compilation: This honestly feels like 100% an Apple issue for not providing the libraries needed in the SDK for cross compilation. I'm also not smart enough to figure out how to inject those into the SDK. It's also too bad WebView2 was never made available for Linux and Mac, but even worse Microsoft never opensourced it either. You can legally download Xcode by creating an Apple account (no device required) then extract the SDK from it. I don't think that breaks ULA, but still objc and resolv issue persists... |
|
@jidckii I think I have the magic zig args for cross compiling to Darwin. I haven't tested it with wails yet, but it's working with WebView and squeek dialog which uses Cocoa. Also didn't need to set CGO_CFLAGS, CGO_CXXFLAGS, or CGO_LDFLAGS at all.
You can check out my docker file for the full build. https://gitlab.com/figuerom16/litequack/-/blob/main/docker/darwin |
|
I forgot about this. Still in early development. Maybe you could take a look at RavynOS Xcode toolchain @leaanthony . https://github.com/ravynsoft/ravynos/releases/tag/SDK_0.7.0.0 |
Wails v3 Cross-Compilation (Linux → macOS)One-time setup — builds the Docker image with Zig cross-compiler + macOS SDK 14.5: wails3 task setup:dockerThen build normally — the build system detects you are not on macOS and uses Docker automatically: # Apple Silicon (arm64)
wails3 build GOOS=darwin GOARCH=arm64
# Intel (amd64)
wails3 build GOOS=darwin GOARCH=amd64
# Universal binary (both architectures)
wails3 task darwin:build:universalNo manual Zig flags or toolchain wrangling needed — the Taskfile handles it all. The Docker image uses Zig as the cross-compiler and includes the macOS SDK sourced from joseluisq/macosx-sdks. Caveats:
See the v3 cross-platform build guide for full details and troubleshooting. |
@jidckii I think I have the magic zig args for cross compiling to Darwin. I haven't tested it with wails yet, but it's working with WebView and squeek dialog which uses Cocoa. Also didn't need to set CGO_CFLAGS, CGO_CXXFLAGS, or CGO_LDFLAGS at all.
ENV ZIG_ARGS="-isysroot ${SDK_DIR} -iwithsysroot /usr/include -L${SDK_DIR}/usr/lib -iframeworkwithsysroot /System/Library/Frameworks -F${SDK_DIR}/System/Library/Frameworks"You can check out my docker file for the full build. https://gitlab.com/figuerom16/litequack/-/blob/main/docker/darwin