Skip to content

Go programs cache the static library and do not automatically use the updated version. #73843

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
ideazh opened this issue May 23, 2025 · 2 comments
Labels
BugReport Issues describing a possible bug in the Go implementation.

Comments

@ideazh
Copy link

ideazh commented May 23, 2025

Go version

go version go1.24.3 linux/amd64

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=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build50930955=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/home/user/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/user/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/user/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.3'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

abc.go

package abc
/*
#cgo LDFLAGS: -L/path/to/build -labc
*/
import "C"

func Abc() {
    C.abc()
}

abc_test.go

package abc

func TestAbc(t *testing.T) {
    Abc()
}

What did you see happen?

The above code can successfully call the C function, but when I rebuild the libabc.a library, the unit tests still use the old libabc.a file. Even deleting the libabc.a file doesn't prevent the program from running.
I tried running go clean -cache, but it didn't work. Running go clean -cache -modcache does force the use of the new library, but rebuilding the program after running go clean -cache -modcache takes a very long time. If every modification to the library requires such a lengthy rebuild, it's unacceptable. How can this be resolved?

What did you expect to see?

Linked library changes should apply instantly, no cache clearing needed.

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label May 23, 2025
@seankhliao
Copy link
Member

I believe go clean -cache should work, -mod cache doesn't make sense.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation.
Projects
None yet
Development

No branches or pull requests

3 participants