-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
linkingos-macosmacOSmacOSupstreamAn issue with a third party project that Zig uses.An issue with a third party project that Zig uses.
Description
Currently we cannot compile CGo programs to MacOS (at least x86_64) with default settings:
- linker arg
-no_pieis discussed in [MachO] error: unsupported linker arg: -no_pie #15438. - DWARF generation: this issue.
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 -ldflags=-buildmode=pie .
# example.com/x
/usr/local/go/pkg/tool/linux_amd64/link: /usr/local/go/pkg/tool/linux_amd64/link: running dsymutil failed: exec: "dsymutil": executable file not found in $PATH
We can make it work by adding -w to the linker flags:
$ go tool link -h |& grep -- -w
-w disable DWARF generation
$ CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 CC="zig cc -target x86_64-macos-none" go build -ldflags="-w -buildmode=pie" .
$ file ./x
./x: Mach-O 64-bit x86_64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|PIE>
Metadata
Metadata
Assignees
Labels
linkingos-macosmacOSmacOSupstreamAn issue with a third party project that Zig uses.An issue with a third party project that Zig uses.