See also the followup post: https://zig.news/kristoff/building-sqlite-with-cgo-for-every-os-4cic
For the last couple of months I worked on a redes...
For further actions, you may consider blocking this person and/or reporting abuse
I run this command to cross compile from window to linux but it doesn't work.
go version go1.17 windows/amd64
$ env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC=
zig cc -target x86_64-linux
CXX=
zig c++ -target x86_64-linux
` go buildoutput :
zig: error: no input files
zig: error: no input files
Turns out the required patch did not land in Go 1.17 so you will have to use the workaround still, sorry! I've updated the article.
Does this support cross compiling from linux to darwin? I can't make it work.
I followed your script workaround, except I swapped -target x86_64-linux with x86_64-macos.
I run:
GOARCH=amd64 CGO_ENABLED=1 GOOS=darwin CC="zcc" CXX="zxx" go build -buildmod
e=c-shared -o test.dll
And I get the error:
/usr/local/go/pkg/tool/linux_amd64/link: running zcc failed: exit status 1
warning: unsupported linker arg: -headerpad
warning: unsupported linker arg: 1144
warning: unsupported linker arg: --compress-debug-sections=zlib-gnu
Cannot open /tmp/go-link-029541769/go.o: bad relocation (no atom found for defined symbol) in section TEXT/text (r_address=5024, r_type=1, r_extern=1, r_length=2, r_pcrel=1, r_symbolnum=620)
error: FileNotFound
Generally speaking, yes, Zig can also crosscompile for macOS. You might have encountered a bug in Zig or maybe it's a problem related to the dll file you're providing (IIRC ARM M1 macs need position independent code, for example).
I recommend trying with a recent build of Zig (you can get nightlies from the official website) and if it's still broken there, then open an issue on GitHub.
I developed a small tool to automatically judge the compilation target based on the GOOS GOARCH environment.
github.com/dosgo/zigtool
Does this work on M1?
Woah! The more I learn about what Zig is capable of, the more it continues to amaze me.
this is quite nice!
Hi, I am running all the commands above.
Process:
brew install zig
added zip dir to path
building docker image (linux/amd64) of go1.18.2-alpine3.14 (so same as the example, with go 1.18 or above) on a macbook m1 machine.
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC="zig cc -target x86_64-linux" CXX="zig c++ -target x86_64-linux" \
go build --tags extended -ldflags="-w -s" -o app.go
Getting this error:
runtime/cgo
cgo: C compiler "zig" not found: exec: "zig": executable file not found in $PATH
Anyone knows what might be wrong? Any direction?
Thanks!
This is nice
For folks wondering about Rust cross-compilation, see also the fantastic cargo-zigbuild
Now I just wish there was a way to do the macos notarization nonsense without macos access…