LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 /* | 5 /* |
6 | 6 |
7 Cgo enables the creation of Go packages that call C code. | 7 Cgo enables the creation of Go packages that call C code. |
8 | 8 |
9 Usage: cgo [compiler options] file.go | 9 Usage: cgo [compiler options] file.go |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 by $GOOS, $GOARCH, or $GOOS/$GOARCH are only defined in matching | 29 by $GOOS, $GOARCH, or $GOOS/$GOARCH are only defined in matching |
30 systems. For example: | 30 systems. For example: |
31 | 31 |
32 // #cgo CFLAGS: -DPNG_DEBUG=1 | 32 // #cgo CFLAGS: -DPNG_DEBUG=1 |
33 // #cgo linux CFLAGS: -DLINUX=1 | 33 // #cgo linux CFLAGS: -DLINUX=1 |
34 // #cgo LDFLAGS: -lpng | 34 // #cgo LDFLAGS: -lpng |
35 // #include <png.h> | 35 // #include <png.h> |
36 import "C" | 36 import "C" |
37 | 37 |
38 Alternatively, CFLAGS and LDFLAGS may be obtained via the pkg-config | 38 Alternatively, CFLAGS and LDFLAGS may be obtained via the pkg-config |
39 tool using a #cgo directive with the package names: | 39 tool using a '#cgo pkg-config:' directive followed by the package names. |
| 40 For example: |
40 | 41 |
41 // #cgo pkg-config: png cairo | 42 // #cgo pkg-config: png cairo |
42 // #include <png.h> | 43 // #include <png.h> |
43 import "C" | 44 import "C" |
44 | 45 |
45 Within the Go file, C identifiers or field names that are keywords in Go | 46 Within the Go file, C identifiers or field names that are keywords in Go |
46 can be accessed by prefixing them with an underscore: if x points at a C | 47 can be accessed by prefixing them with an underscore: if x points at a C |
47 struct with a field named "type", x._type accesses the field. | 48 struct with a field named "type", x._type accesses the field. |
48 | 49 |
49 The standard C numeric types are available under the names | 50 The standard C numeric types are available under the names |
(...skipping 20 matching lines...) Expand all Loading... |
70 Cgo transforms the input file into four output files: two Go source | 71 Cgo transforms the input file into four output files: two Go source |
71 files, a C file for 6c (or 8c or 5c), and a C file for gcc. | 72 files, a C file for 6c (or 8c or 5c), and a C file for gcc. |
72 | 73 |
73 The standard package makefile rules in Make.pkg automate the | 74 The standard package makefile rules in Make.pkg automate the |
74 process of using cgo. See $GOROOT/misc/cgo/stdio and | 75 process of using cgo. See $GOROOT/misc/cgo/stdio and |
75 $GOROOT/misc/cgo/gmp for examples. | 76 $GOROOT/misc/cgo/gmp for examples. |
76 | 77 |
77 Cgo does not yet work with gccgo. | 78 Cgo does not yet work with gccgo. |
78 */ | 79 */ |
79 package documentation | 80 package documentation |
LEFT | RIGHT |