Skip to content
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

cmd/go: document/clarify how go env infers CC and CXX when not set. #37886

Open
thothothotho opened this issue Mar 16, 2020 · 1 comment
Open
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@thothothotho
Copy link

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

$ go version
go version go1.14 linux/amd64

Does this issue reproduce with the latest release?

I don't know

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

go env Output
$ go env
fred@fred-linux:~/src/server/build$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/fred/.cache/go-build"
GOENV="/home/fred/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/fred/go:/home/fred/src/server/Gofred/"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/linuxbrew/.linuxbrew/Cellar/go/1.14/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/linuxbrew/.linuxbrew/Cellar/go/1.14/libexec/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc-5"
CXX="g++-5"
CGO_ENABLED="1"
GOMOD=""
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build142698688=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I probably had gcc-5 as the default compiler on my ubuntu system. Then I did change the default compiler (with update-alternative) so that gcc now invokes gcc-8 (same for g++).

I have some c++ code I try to bridge with cgo that relies on c++ 17. I try to build it this way

 go build -x  -o /home/fred/src/server/build/libcppgow.so -buildmode=c-shared main.go

The output shows me it is using g++-5 (and the build fails, of course). go env also shows:

 CC="gcc-5"
 CXX="g++-5"

Somehow, go does not want to use the default compiler. He might have cache somewhere the default compiler from an earlier invocation. Or it might use the compiler at the time I installed go (using brew).

What did you expect to see?

I expect the CC/CXX are inferred to be the default compiler of the platform.
If I'm wrong, then you should clearly document how CC/CXX are inferred.

@bcmills bcmills changed the title document/clarify how go env infers CC and CXX when not set. cmd/go: document/clarify how go env infers CC and CXX when not set. Mar 16, 2020
@ianlancetaylor
Copy link
Contributor

It's hard to write general documentation here, as it depends on how you install Go.

If you installed Go yourself as described at https://golang.org/doc/install-source.html, see the comments for CC_FOR_TARGET and CXX_FOR_TARGET in src/make.bash.

@bcmills bcmills added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 16, 2020
@bcmills bcmills added this to the Backlog milestone Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants