Closed
Description
What version of Go are you using (go version
)?
$ go version go version go1.15.5 linux/amd64
Does this issue reproduce with the latest release?
Yes, with Go 1.15.5 released a few days ago.
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/ayke/.cache/go-build" GOENV="/home/ayke/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/ayke/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/ayke:/home/ayke" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" 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-build201769525=/tmp/go-build -gno-record-gcc-switches"
What did you do?
I put two files in a new directory.
main.go
:
package main
// void hello(void);
import "C"
func main() {
C.hello()
}
main.cpp
:
#include <cstdio>
extern "C"
void hello(void) {
printf("hello!\n");
}
And then I ran this code using
CGO_LDFLAGS=-std=c++14 go run .
What did you expect to see?
The following message should be printed:
hello!
This works in Go 1.15.4 at least. I've also tested some version of Go 1.14 in which it works.
What did you see instead?
go build runtime/cgo: invalid flag in go:cgo_ldflag: -std=c++14
It seems to me that -std=c++14
is a perfectly safe flag, I've been using it for quite some time.
I suspect #42562 is the cause.