Hi!
I’m trying to compile a hello world CGO program using the zig toolchain. (My ultimate goal is to cross compile a CGO app to Linux/Mac, ARM/x86, but baby steps)
I get an error when compiling with zig.
The program is
package main
import "C"
import "fmt"
func main() {
fmt.Println(C.int(10))
}
My build command is
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 CC="zig cc -target x86_64-macos" CXX="zig c++ -target x86_64-macos" go build
and the error is
warning: unsupported linker arg: -headerpad
warning: unsupported linker arg: 1144
warning: unsupported linker arg: -no_pie
warning: unsupported linker arg: -pagezero_size
warning: unsupported linker arg: 4000000
/usr/local/go/pkg/tool/darwin_amd64/link: /usr/local/go/pkg/tool/darwin_amd64/link: running dsymutil failed: exit status 1
LLVM ERROR: Malformed MachO file.
My system:
- Macos Catalina 10.15.7
- Apple clang version 12.0.0
- zig 0.9.1
- go version go1.18 darwin/amd64
I’ve tried a variety of things, setting sysroot flag etc. But no joy yet. Presumably there is a simple config I’m missing. Any help appreciated.
[cross posted from reddit]