Description
What did you do?
I updated my Go installation from 1.8 to 1.10.1. I used the officially provided archive (go1.10.1.linux-amd64.tar.gz) for Linux x86-64 from https://golang.org/dl/.
When I try to use the "net/http" package in a file go build -i
prints the following error go build runtime/cgo: open /usr/local/go/pkg/linux_amd64/runtime/cgo.a: permission denied
. If I just run go build
without -i
or if I downgrade to Go 1.9.5 and run the command the error does not appear and everything builds without errors.
The following code can be used to reproduce the issue:
package main
import (
"fmt"
"net/http"
)
func main() {
s := http.StatusOK
fmt.Println(s)
}
I further investigated this issue and tried to reproduce it on the Linux machines of two friends. We discovered that the issue only occurs if the following environment variable values are set: CC="clang"
and CXX="clang++"
. If those variables are set to CC="gcc"
and CXX="g++"
the command runs as expected without errors.
What did you expect to see?
No error and a compiled binary.
What did you see instead?
The following error message and no binary.
go build runtime/cgo: open /usr/local/go/pkg/linux_amd64/runtime/cgo.a: permission denied
System details
go version go1.10.1 linux/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/tobias/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/tobias/Code/GoWorkspace"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build742161429=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.10.1 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.10.1
uname -sr: Linux 4.15.17-300.fc27.x86_64
LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: Fedora
Description: Fedora release 27 (Twenty Seven)
Release: 27
Codename: TwentySeven
/lib64/libc.so.6: GNU C Library (GNU libc) stable release version 2.26, by Roland McGrath et al.
lldb --version: lldb version 5.0.1
gdb --version: GNU gdb (GDB) Fedora 8.0.1-36.fc27
Activity
[-]go build -i returning error if "net/http" is imported and clang set in CC and CXX[/-][+]cmd/cgo: go build -i returning error if "net/http" is imported and clang set in CC and CXX[/+][-]cmd/cgo: go build -i returning error if "net/http" is imported and clang set in CC and CXX[/-][+]cmd/go: go build -i returning error if "net/http" is imported and clang set in CC and CXX[/+]ianlancetaylor commentedon Apr 27, 2018
It would be nice to fix this, though at the moment I don't see how.
ianlancetaylor commentedon Apr 27, 2018
Note that there isn't much reason to use
go build -i
with 1.10, so I certainly recommend omitting the-i
option as a workaround.tms320 commentedon May 27, 2018
I have the same problem on Raspbian. I use LiteIDE. To eliminate the problem I had to modify the file:
~/liteide/build/liteide/share/liteide/litebuild/gosrc.xml
I removed '-i' option in these lines:
<custom id="BuildArgsi" name="BUILDARGS" value="-i" shared-value="$(BUILDFLAGS)"/>
<custom id="ForceBuildArgsi" name="FORCEBUILDARGS" value="-i -a -v" shared-value="$(BUILDFLAGS)"/>
tms320 commentedon Jun 6, 2018
The author of Lite IDE helped me to solve the problem on Raspberry Pi 3:
visualfc/liteide#946
I built and installed 'std ' using the following command:
sudo GOOS=linux GOARCH=arm GOARM=6 go install std
And the problem was eliminated.
mahnve commentedon Sep 23, 2018
I have the same problem, even with CC="gcc" and CXX="g++"
5 remaining items
bcmills commentedon May 8, 2019
We should make this change, but not during the freeze. It'll have to slip another release.
bcmills commentedon Feb 24, 2023
As of Go 1.20, standard-library packages no longer have an install target, and
go build
no longer accepts the-i
flag. I think this issue is now moot, but please let me know if there's still something to do here.