if len(info.CgoFiles) > 0 {
cgoFiles := b.abss(info.CgoFiles...)
s.addInput(cgoFiles...)
- outGo, outObj := b.cgo(cgoFiles)
+ cgoCFiles := b.abss(info.CFiles...)
+ s.addInput(cgoCFiles...)
+ outGo, outObj := b.cgo(cgoFiles, cgoCFiles)
gofiles = append(gofiles, outGo...)
ofiles = append(ofiles, outObj...)
s.addIntermediate(outGo...)
var cgoRe = regexp.MustCompile(`[/\\:]`)
-func (b *build) cgo(cgofiles []string) (outGo, outObj []string) {
+func (b *build) cgo(cgofiles, cgocfiles []string) (outGo, outObj []string) {
// cgo
// TODO(adg): CGOPKGPATH
// TODO(adg): CGO_FLAGS
b.script.addIntermediate(ofile)
}
}
+ for _, cfile := range cgocfiles {
+ ofile := b.obj + cgoRe.ReplaceAllString(cfile[:len(cfile)-1], "_") + "o"
+ b.gccCompile(ofile, cfile)
+ linkobj = append(linkobj, ofile)
+ outObj = append(outObj, ofile)
+ }
dynObj := b.obj + "_cgo_.o"
b.gccLink(dynObj, linkobj...)
b.script.addIntermediate(dynObj)
--- /dev/null
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+int
+Add(int x, int y, int *sum)
+{
+ sum = x+y;
+}
/*
char* greeting = "hello, world";
*/
+// #include "cgotest.h"
import "C"
+import "unsafe"
var Greeting = C.GoString(C.greeting)
+
+func DoAdd(x, y int) (sum int) {
+ C.Add(C.int(x), C.int(y), (*C.int)(unsafe.Pointer(&sum)))
+ return
+}
--- /dev/null
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+extern int Add(int, int, int *);