Skip to content

[MachO] error: unsupported linker arg: -no_pie #15438

@motiejus

Description

@motiejus

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-x86_6464-bit x86enhancementSolving this issue will likely involve adding new logic or components to the codebase.linkingos-macosmacOS

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions