Currently we cannot compile CGo programs to MacOS (at least x86_64) with default settings. Example Go file:
main.go
package main
// #include <stdio.h>
// char* hello() { return "hello, world"; }
// void phello() { printf("%s\n", hello()); }
import "C"
func main() {
C.phello()
}
func Chello() string {
return C.GoString(C.hello())
}
Compile to MacOS
$ CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 CC="zig cc -target x86_64-macos-none" go build .
# example.com/x
/usr/local/go/pkg/tool/linux_amd64/link: running zig failed: exit status 1
error: unsupported linker arg: -no_pie
Currently we cannot compile CGo programs to MacOS (at least x86_64) with default settings. Example Go file:
main.go
Compile to MacOS