go/loader: don't pass ldflags to cgo
Although these flags are harmless on linux, they
cause clang on darwin to issue an error about
unused flags (-lpthread). We only care about compilation
so we don't need them.
Change-Id: I0fc756e2f4d7a829d43b5aa912c4e4b24a802a1c
Reviewed-on: https://go-review.googlesource.com/21283
Reviewed-by: Robert Griesemer <gri@golang.org>
diff --git a/go/loader/cgo.go b/go/loader/cgo.go
index c925ace..245b914 100644
--- a/go/loader/cgo.go
+++ b/go/loader/cgo.go
@@ -115,16 +115,15 @@
// Objective C, CGOPKGPATH, CGO_FLAGS.
//
func runCgo(bp *build.Package, pkgdir, tmpdir string) (files, displayFiles []string, err error) {
- cgoCPPFLAGS, _, _, cgoLDFLAGS := cflags(bp, true)
+ cgoCPPFLAGS, _, _, _ := cflags(bp, true)
_, cgoexeCFLAGS, _, _ := cflags(bp, false)
if len(bp.CgoPkgConfig) > 0 {
- pcCFLAGS, pcLDFLAGS, err := pkgConfigFlags(bp)
+ pcCFLAGS, err := pkgConfigFlags(bp)
if err != nil {
return nil, nil, err
}
cgoCPPFLAGS = append(cgoCPPFLAGS, pcCFLAGS...)
- cgoLDFLAGS = append(cgoLDFLAGS, pcLDFLAGS...)
}
// Allows including _cgo_export.h from .[ch] files in the package.
@@ -150,7 +149,7 @@
args := stringList(
"go", "tool", "cgo", "-objdir", tmpdir, cgoflags, "--",
- cgoCPPFLAGS, cgoLDFLAGS, cgoexeCFLAGS, bp.CgoFiles,
+ cgoCPPFLAGS, cgoexeCFLAGS, bp.CgoFiles,
)
if false {
log.Printf("Running cgo for package %q: %s (dir=%s)", bp.ImportPath, args, pkgdir)
diff --git a/go/loader/cgo_pkgconfig.go b/go/loader/cgo_pkgconfig.go
index 91ab2cc..de57422 100644
--- a/go/loader/cgo_pkgconfig.go
+++ b/go/loader/cgo_pkgconfig.go
@@ -29,17 +29,11 @@
return
}
-// pkgConfigFlags calls pkg-config if needed and returns the cflags/ldflags needed to build the package.
-func pkgConfigFlags(p *build.Package) (cflags, ldflags []string, err error) {
- if pkgs := p.CgoPkgConfig; len(pkgs) > 0 {
- cflags, err = pkgConfig("--cflags", pkgs)
- if err != nil {
- return nil, nil, err
- }
- ldflags, err = pkgConfig("--libs", pkgs)
- if err != nil {
- return nil, nil, err
- }
+// pkgConfigFlags calls pkg-config if needed and returns the cflags
+// needed to build the package.
+func pkgConfigFlags(p *build.Package) (cflags []string, err error) {
+ if len(p.CgoPkgConfig) == 0 {
+ return nil, nil
}
- return
+ return pkgConfig("--cflags", p.CgoPkgConfig)
}