Skip to content

cmd/build: cgo cross build need to explictly set CGO_ENABLED=1 #72988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
linsite opened this issue Mar 21, 2025 · 1 comment
Closed

cmd/build: cgo cross build need to explictly set CGO_ENABLED=1 #72988

linsite opened this issue Mar 21, 2025 · 1 comment

Comments

@linsite
Copy link
Contributor

linsite commented Mar 21, 2025

Go version

go version go1.24.1 linux/arm64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE='on'
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/ulin/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/ulin/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1300834282=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/mnt/data/lean/g/excersize/go.mod'
GOMODCACHE='/home/ulin/gosrc/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/ulin/gosrc'
GOPRIVATE=''
GOPROXY='https://goproxy.cn'
GOROOT='/usr/local/go'
GOSUMDB='off'
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/ulin/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='go1.24.1'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

cross compiling a tiny cgo program for riscv64.

package main

/*
#include <stdio.h>
#include <stdlib.h>

// A C function
void myprint() {
 printf("env: PATH=%s\n", getenv("PATH"));
}
*/
import "C"

func main() {
C.myprint()
}

CC=/usr/bin/riscv64-linux-gnu-gcc GOARCH=riscv64 go build m.go

What did you see happen?

go: no Go source files

What did you expect to see?

As the default CGO_ENABLED=1 showed in go env, the build should succeed.
But need to explicitly set CGO_ENABLED=1 in the build command.

FYI, go build complained "no Go source files" doesn't convey any useful information for one to figure out what's going wrong.

@linsite
Copy link
Contributor Author

linsite commented Mar 21, 2025

I wonder if this can be covered by #48540?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants