go: cmd/cgo: rt0_go failure on Windows when using zig cc
Hello, any Go developers interested in working with Zig developers on this use case?
Upstream issue: https://github.com/ziglang/zig/issues/7874 Tested with go 1.15.5.
main.go
package main
//int Add(int a, int b){
// return a+b;
//}
import "C"
import "fmt"
func main() {
a := C.int(10)
b := C.int(20)
c := C.Add(a, b)
fmt.Println(c) // 30
}
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC="zcc" CXX="zc++" go build main.go
zcc
#!/bin/sh
zig cc -target x86_64-windows-gnu $@
zc++
#!/bin/sh
zig c++ -target x86_64-windows-gnu $@
output:
# command-line-arguments
warning: unsupported linker arg: --compress-debug-sections=zlib-gnu
It produces main.exe
but when run it segfaults in runtime.rt0_go()
(called from main()). Expected output is to print “30” to the console when run in cmd.exe.
Happy to chat on IRC or Discord if anyone has some ideas to try.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 22 (9 by maintainers)
Let’s keep this issue open until we know if this is a bug in zig or in Go.
@zx2c4 as we found that your version works, maybe link/mention the relevant bugs here so Github can help us keep track if we can close this bug?
Reproduced with go 1.15.6 linux/amd64, full output here: https://pastebin.com/BmVtawS1
@mdempsky Assuming you have go installed already, all you should need is a master copy of zig. For you this probably means getting a binary from https://ziglang.org/download/ and adding it to your path (shouldn’t need any more setup than this). Personally I get my version from the “zig-git” aur package.