You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I compiled this hello.go with GOOS=linux GOARCH=amd64 go build hello.go. This worked perfectly but it was a little bit slow. It takes 2 to 3 secs to build this simple program because this command always builds all dependencies from source code.
So, I tried -pkgdir option of go build. I expected the cross-compiled packages will be stored and reused from -pkgdir.
I ran the following command
GOOS=linux GOARCH=amd64 go build -i -v -pkgdir cache hello.go
It looks like the bug occurs when there are no cross-compilation .a files in the GOROOT and you pass a relative path to -pkgdir. Testing here on macOS:
cd /tmp
$ GOOS=linux go build -i -pkgdir /tmp/mycache main.go # works
$ rm -rf mycache
$ GOOS=linux go build -i -pkgdir mycache main.go
runtime/internal/sys
runtime/internal/atomic
runtime
# runtime
/Users/crawshaw/go/src/runtime/alg.go:8:2: can't find import: "runtime/internal/sys"
(As an aside, you describe using -pkgdir to get cross-compilation caching. You don't need -pkgdir for that if your GOROOT is writable. Just use -i. The intermediate stdlib packages are saved in $GOROOT/pkg/GOOS_GOARCH/.)
What version of Go are you using (
go version
)?go version go1.8.3 darwin/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
I cross compiled Go into Linux binary on MacOSX.
I compiled this hello.go with
GOOS=linux GOARCH=amd64 go build hello.go
. This worked perfectly but it was a little bit slow. It takes 2 to 3 secs to build this simple program because this command always builds all dependencies from source code.So, I tried -pkgdir option of go build. I expected the cross-compiled packages will be stored and reused from
-pkgdir
.I ran the following command
and just got an error message
What did you expect to see?
-pkgdir
works withGOOS=linux GOARCH=amd64
environment variables and improves build speed.What did you see instead?
It seems go build failed to load
runtime/internal/sys.a
from -pkgdir when it compiledruntime
.The text was updated successfully, but these errors were encountered: