Skip to content

Linker error when using zig to compile a CGo program on a Mac #11303

@kaidaguerre

Description

@kaidaguerre

Zig Version

0.9.1

Steps to Reproduce

I'm trying to compile a hello world CGO program using the zig toolchain.

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

My system:

  • Macos Catalina 10.15.7
  • Apple clang version 12.0.0
  • zig 0.9.1
  • go version go1.18 darwin/amd64

Expected Behavior

the program builds

Actual Behavior

the build fails with a link error

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.


Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-x86_6464-bit x86bugObserved behavior contradicts documented or intended behaviorlinkingos-macos

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions