Skip to content

cgo build failed when cc='zig cc' #20243

@jiacai2050

Description

@jiacai2050

Zig Version

0.14.0-dev.6+0ba64e9ce

Steps to Reproduce and Observed Behavior

package main

// #include <stdio.h>
// #include <stdlib.h>
//
// static void myprint(char* s) {
//   printf("%s\n", s);
// }
import "C"
import "unsafe"

func main() {
	cs := C.CString("Hello from stdio")
	C.myprint(cs)
	C.free(unsafe.Pointer(cs))
}

Given this file, compile with

CC='zig cc' go build main.go

it will throw following errors on my machine:

# command-line-arguments
/Users/jiacai/.asdf/installs/golang/1.22.4/go/pkg/tool/darwin_arm64/link: running zig failed: exit status 1
error: symbol _runtime.covctrs not attached to any (sub)section
    note: while parsing /var/folders/50/12rf3hkj2n10whhf8l63nnyh0000gn/T/go-link-3691128890/go.o

Expected Behavior

Build OK

$ go version
go version go1.22.4 darwin/arm64

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorlinkingos-macosmacOS

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions