cmd/link: building a package that uses cgo errors out with "cannot implicitly include runtime/cgo in a shared library" #47183
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
What version of Go are you using (
go version
)?This issue was also reproduced with
1.15.10
and1.17beta1
.Does this issue reproduce with the latest release?
No: the same code couldn't reproduce the same error on a Debian virtual machine, but a different error was returned. See the other section below.Yes, but only before running
go install -buildmode=shared -linkshared std
.What operating system and processor architecture are you using (
go env
)?go env
Output/etc/os-release
lscpu
OutputWhat did you do?
This issue was opened for two errors: a
cannot implicitly include runtime/cgo in a shared library
error and acap out of range
error inloader.(*Loader).LoadSyms
.When building this file at
c/c.go
:using the command
go build -buildmode=shared -linkshared ./c
, the following error is returned:The same error is returned when adding
import _ "runtime/cgo"
.With this code at
./main.go
:built using
go build -linkshared .
, a similar error is returned:What did you expect to see?
The first library code built with
go build -buildmode=shared -linkshared ./c
should succeed, and so should building the main executable withgo build -linkshared .
. The main executable should be small and dynamically linklibstd.so
from somewhere else.What did you see instead?
The two above errors:
This section describes an attempt at reproducing the above bug after running
go install -buildmode=shared -linkshared std
.What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
Output/etc/os-release
What did you do?
See the above section.
What did you expect to see?
See the above section.
What did you see instead?
Building
package c
yielded amakeslice: cap out of range
panic:The binary actually built successfully with the expected linking:
The text was updated successfully, but these errors were encountered: