golang/go

cmd/go: installed c-shared libraries receiving ".a" suffix on Linux

Open

#24,253 opened on Mar 5, 2018

View on GitHub
 (4 comments) (2 reactions) (0 assignees)Go (19,008 forks)batch import
GoCommandNeedsFixhelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

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

go version go1.9.4 linux/amd64

Does this issue reproduce with the latest release?

Yes. Reproduced with 1.10

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

GOARCH="amd64"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build706877829=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

go install -buildmode=c-shared -x -a ./libpa

libpa contains a a C library declared in a main package.

What did you expect to see?

I expected the output file to be labeled libpa.so indicating it was a shared object

What did you see instead?

The output was labeled libpa.a indicating an archive file, but in actuality it was a shared object file.

file $GOPATH//pkg/linux_amd64_shared/<pkg dir>/libpa.a
libpa.a: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=31934079c8d80546780a304c28421f0d8228c9a4, not stripped

Additional Information

  • go build -buildmode=c-shared -o libpa.so -x -a ./libpa produces the expected libpa.so output. This is how .so files are generated in cshared_test.go.
  • go install -buildmode=c-archive -x -a ./libpa produces an archive file correctly named libpa.a
  • init.go leaves the cfg.ExeSuffix empty for Linux machines when the c-shared option is selected (sets it to ".a" for c-archive).
  • Passing GOEXE=".so" does not appear to overwrite the cfg.ExeSuffix.

Contributor guide