mirror of
https://github.com/golang/go
synced 2024-11-18 10:44:45 -07:00
cmd/cgo: wrap generated exports with extern "C" for C++
This will make it possible for C++ code to #include the export header file and see the correct declarations. The preamble remains the user's responsibility. It would not be appropriate to wrap the preamble in extern "C", because it might include header files that work with both C and C++. Putting those header files in an extern "C" block would break them. Change-Id: Ifb40879d709d26596d5c80b1307a49f1bd70932a Reviewed-on: https://go-review.googlesource.com/9850 Reviewed-by: Minux Ma <minux@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: David Crawshaw <crawshaw@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
fd392ee52b
commit
e8fc93ea45
@ -846,6 +846,8 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) {
|
||||
fmt.Fprint(fgo2, "}\n")
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(fgcch, "%s", gccExportHeaderEpilog)
|
||||
}
|
||||
|
||||
// Write out the C header allowing C code to call exported gccgo functions.
|
||||
@ -1009,6 +1011,8 @@ func (p *Package) writeGccgoExports(fgo2, fm, fgcc, fgcch io.Writer) {
|
||||
fmt.Fprint(fgo2, ")\n")
|
||||
fmt.Fprint(fgo2, "}\n")
|
||||
}
|
||||
|
||||
fmt.Fprintf(fgcch, "%s", gccExportHeaderEpilog)
|
||||
}
|
||||
|
||||
// writeExportHeader writes out the start of the _cgo_export.h file.
|
||||
@ -1374,6 +1378,17 @@ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
|
||||
#endif
|
||||
|
||||
/* End of boilerplate cgo prologue. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
`
|
||||
|
||||
// gccExportHeaderEpilog goes at the end of the generated header file.
|
||||
const gccExportHeaderEpilog = `
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
`
|
||||
|
||||
// gccgoExportFileProlog is written to the _cgo_export.c file when
|
||||
|
Loading…
Reference in New Issue
Block a user