go icon indicating copy to clipboard operation
go copied to clipboard

cmd/link: cannot find runtime/cgo for c-archive, c-shared

Open ii64 opened this issue 3 years ago • 1 comments

What version of Go are you using (go version)?

$ go version
go version go1.19 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ii64/.cache/go-build"
GOENV="/home/ii64/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ii64/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ii64/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19"
GCCGO="/usr/local/bin/gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/hh/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build475420545=/tmp/go-build -gno-record-gcc-switches"

What did you do?

go build -buildmode=c-archive hh
go build -buildmode=c-shared hh

hh is a main package.

What did you expect to see?

Works just fine like -buildmode=plugin and -buildmode=exe

What did you see instead?

$ go build -buildmode=c-archive hh
# hh
loadinternal: cannot find runtime/cgo

ii64 avatar Aug 08 '22 02:08 ii64

Does the build complete? This print is not an error and does not terminate the build. (See #31544)

Does your program not use cgo (import "C")? It is probably not very useful to build a program in c-archive or c-shared mode without using cgo, as it does not export any function to C code to call.

cherrymui avatar Aug 08 '22 17:08 cherrymui

Thank you, and yes I am not importing "C" and set CGO_ENABLED=0, it does not stop the build process. Closing this as it works as intended.

ii64 avatar Aug 21 '22 14:08 ii64