-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
Cross-compiling from Windows to Mac #497
Comments
Hi @kkevinchou, we haven't tried to cross-compile from Windows to other OS. Perhaps using the Windows Subsystem for Linux, you could use the Linux to macOS method of cross-compilation? |
Thanks for the suggestion, I was hoping for something a little more out-of-the-box but that's a reasonable workaround 👍 |
Sorry about that! It is because cross-compiling to macOS requires macOS' toolchain to do it. I'll write the steps here if you plan to try that method:
And then update PATH like this:
After that you should be able to cross-compile to macOS though I haven't fully tested those steps myself. Let me know if you encounter any problem!
There's on-going progress in implementing it for |
When I try with the above on a docker container I first get several linker warnings about the static libs being on newer osx versions than the binary being linked and then the linking fails on sdl_mixer with:
Trying to setup a CI macos build up for my project so that I wouldn't have to manually create the macos builds, and gitlab doesn't yet offer macos runners. |
Hi @depili, are you perhaps using the |
That was with 0.4.1 initially, tried 0.4.10 also but still getting the same error on the linking stage. For reference my Dockerfile is
and the project in question that I'm trying to cross compile is https://gitlab.com/Depili/clock-8001 |
and to be specific the the v4/cmd/sdl-clock of that project. |
Hi @depili, sorry for taking so long to reply! I added a commit that seems to fix the undefined symbol issue. Could you try the If you still have issues, would you please open another issue? We can continue discuss it there 🙂 |
Seems to have fixed that linking error, now just running into other issues on my osx-crossbuild with (supposedly) the golang builtin time package...
But this is probably unrelated to the go-sdl2 in of itself, just some other issue with osxcross and golang. |
Actually, doing a quick test and just trying to compile the example from go-sdl2 readme results in linking errors with _clock_gettime:
Just compiling a go program printing out time.Now(), runtime.GOOS and runtime.ReadBuildInfo() works when cross-compiled with osxcross. |
Using git head (e59a63461da2cbc20cb0a5bbfc954730e50a5472) of osxcross, if that matters. |
Hi @depili, you're right. It seems like macOS SDK 10.11 can't be used, at least with the Go 1.17. I was able to compile with macOS SDK 11.3 but I think any SDK version 10.13 or newer should work which seems to be requirement for Go 1.17 (https://golang.org/doc/go1.17). It might also work with an older Go versions like 1.16 if we don't want to upgrade the macOS SDK. I used this code as a test:
|
Unfortunately, I can't seem to get osxcross up with 10.13 as
`build_compiler_rt.sh` fails, so can't test. Will try with go 1.16
|
Trying with go1.16.9 and SDK 10.11 still runs into a linking problem, just
one this time:
```
***@***.***:~/clock-8001/v4# cat foo.go
package main
import "github.com/veandco/go-sdl2/sdl"
func main() {
if err := sdl.Init(sdl.INIT_EVERYTHING); err != nil {
panic(err)
}
defer sdl.Quit()
window, err := sdl.CreateWindow("test",
sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
800, 600, sdl.WINDOW_SHOWN)
if err != nil {
panic(err)
}
defer window.Destroy()
surface, err := window.GetSurface()
if err != nil {
panic(err)
}
surface.FillRect(nil, 0)
rect := sdl.Rect{0, 0, 200, 200}
surface.FillRect(&rect, 0xffff0000)
window.UpdateSurface()
running := true
for running {
for event := sdl.PollEvent(); event != nil; event =
sdl.PollEvent() {
switch event.(type) {
case *sdl.QuitEvent:
println("Quit")
running = false
break
}
}
}
}
***@***.***:~/clock-8001/v4# CGO_ENABLED=1
CC=x86_64-apple-darwin15-clang GOOS=darwin GOARCH=amd64 go build -tags
static -ldflags "-s -w" foo.go
# command-line-arguments
/usr/local/go/pkg/tool/linux_amd64/link: running
x86_64-apple-darwin15-clang failed: exit status 1
Undefined symbols for architecture x86_64:
"_clock_gettime", referenced from:
_runtime.walltime_trampoline in go.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
```
Will need to see if I can get any SDK other than 10.11 up with osxcross,
can't go lower than go 1.16 since I use embed that requires go 1.16
|
Finally had success, using `liushuyu/osxcross` container that is based on
10.14 SDK and go 1.16. For some reason my attempts of creating the SDK
tarballs via the osxcross/tools/ scripts resulted always in something
non-functional in the end.
|
Hello is there any guidance for cross-compiling from Windows to Mac? I get the following error:
I am using MinGW
The text was updated successfully, but these errors were encountered: