mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/cgo: check whether C compiler exists
Currently we print a cryptic message if a C compiler doesn't exist. This patch adds more graceful handling. Fixes #44271 Change-Id: I44f16ef6eb2853fee22fa1d996e41ec6c9ee82f1 Reviewed-on: https://go-review.googlesource.com/c/go/+/301249 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
parent
a5df88355c
commit
4313c28861
1 changed files with 9 additions and 0 deletions
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
@ -302,6 +303,14 @@ func main() {
|
||||||
|
|
||||||
p := newPackage(args[:i])
|
p := newPackage(args[:i])
|
||||||
|
|
||||||
|
// We need a C compiler to be available. Check this.
|
||||||
|
gccName := p.gccBaseCmd()[0]
|
||||||
|
_, err := exec.LookPath(gccName)
|
||||||
|
if err != nil {
|
||||||
|
fatalf("C compiler %q not found: %v", gccName, err)
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
|
|
||||||
// Record CGO_LDFLAGS from the environment for external linking.
|
// Record CGO_LDFLAGS from the environment for external linking.
|
||||||
if ldflags := os.Getenv("CGO_LDFLAGS"); ldflags != "" {
|
if ldflags := os.Getenv("CGO_LDFLAGS"); ldflags != "" {
|
||||||
args, err := splitQuoted(ldflags)
|
args, err := splitQuoted(ldflags)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue