New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: should not require -arch flag for cross compiling to Darwin with cgo #59544
Comments
A stock Linux C toolchain typically cannot compile for macOS. (For one, it lacks the C headers for macOS system libraries.) Can you cross-compile a pure C binary for macOS using your compiler? That's certainly a minimum requirement for being able to cross-compile a |
I think I was confused by the error and PR adding the To follow up to the question of actually cross compiling linux->Darwin, I've found that
However, on my end it still seems that |
There are ARM64-based macOS and x86-64 based macOS. Without passing -arch it is unclear which one you're targeting. Especially on an ARM64-based macOS machine with Rosetta 2 emulation, the default arch choice can be quite confusing and is often not what user whats. So we pass -arch explicitly to make that clear. From the comment above it sounds like you're not using either of the C cross toolchains. Then what do you use? Without a proper C cross toolchain, cross compiling for cgo would not work even if we don't pass -arch. I don't think we're going to change this behavior, at least for now. If you want to use a specific C cross toolchain that works well except -arch, we can see what the best we can do from there. Thanks. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
here is a repro:
Then on any run of the mill linux run
What did you expect to see?
The program compile without error
What did you see instead?
see above. It seems to me the commit https://go-review.googlesource.com/c/go/+/283812 caused this, and that the flag
-arch
should be added when runtime.GOOS is Darwin, not when the env var GOOS is Darwin. I also tried installing clang on linux to get around this, thinking it was clang that accepted-arch
, but that flag appears to be specific to Darwin.The text was updated successfully, but these errors were encountered: