Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(358)

Delta Between Two Patch Sets: src/cmd/cgo/doc.go

Issue 8248043: code review 8248043: cmd/go: Add support for including C++ files in packages (Closed)
Left Patch Set: diff -r fb78cf8fd5b5 https://code.google.com/p/go Created 10 years, 12 months ago
Right Patch Set: diff -r e86ab7e59e50 https://code.google.com/p/go Created 10 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/cmd/go/build.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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: 9 Usage:
10 go tool cgo [compiler options] file.go 10 go tool cgo [compiler options] file.go
11 11
12 The compiler options are passed through uninterpreted when 12 The compiler options are passed through uninterpreted when
13 invoking gcc to compile the C parts of the package. 13 invoking gcc to compile the C parts of the package.
14 14
15 The input file.go is a syntactically valid Go source file that imports 15 The input file.go is a syntactically valid Go source file that imports
16 the pseudo-package "C" and then refers to types such as C.size_t, 16 the pseudo-package "C" and then refers to types such as C.size_t,
17 variables such as C.stdout, or functions such as C.putchar. 17 variables such as C.stdout, or functions such as C.putchar.
18 18
19 If the import of "C" is immediately preceded by a comment, that 19 If the import of "C" is immediately preceded by a comment, that
20 comment, called the preamble, is used as a header when compiling 20 comment, called the preamble, is used as a header when compiling
21 the C parts of the package. For example: 21 the C parts of the package. For example:
22 22
23 // #include <stdio.h> 23 // #include <stdio.h>
24 // #include <errno.h> 24 // #include <errno.h>
25 import "C" 25 import "C"
26 26
27 CFLAGS and LDFLAGS may be defined with pseudo #cgo directives 27 CPPFLAGS, CFLAGS, CXXFLAGS and LDFLAGS may be defined with pseudo #cgo directive s
28 within these comments to tweak the behavior of gcc. Values defined 28 within these comments to tweak the behavior of gcc. Values defined
29 in multiple directives are concatenated together. Options prefixed 29 in multiple directives are concatenated together. Options prefixed
30 by $GOOS, $GOARCH, or $GOOS/$GOARCH are only defined in matching 30 by $GOOS, $GOARCH, or $GOOS/$GOARCH are only defined in matching
31 systems. For example: 31 systems. For example:
32 32
33 // #cgo CFLAGS: -DPNG_DEBUG=1 33 // #cgo CFLAGS: -DPNG_DEBUG=1
34 // #cgo linux CFLAGS: -DLINUX=1 34 // #cgo linux CFLAGS: -DLINUX=1
35 // #cgo LDFLAGS: -lpng 35 // #cgo LDFLAGS: -lpng
36 // #include <png.h> 36 // #include <png.h>
37 import "C" 37 import "C"
38 38
39 Alternatively, CFLAGS and LDFLAGS may be obtained via the pkg-config 39 Alternatively, CPPFLAGS and LDFLAGS may be obtained via the pkg-config
40 tool using a '#cgo pkg-config:' directive followed by the package names. 40 tool using a '#cgo pkg-config:' directive followed by the package names.
41 For example: 41 For example:
42 42
43 // #cgo pkg-config: png cairo 43 // #cgo pkg-config: png cairo
44 // #include <png.h> 44 // #include <png.h>
45 import "C" 45 import "C"
46 46
47 The CGO_CFLAGS and CGO_LDFLAGS environment variables are added 47 The CGO_CPPFLAGS, CGO_CFLAGS, CGO_CXXFLAGS and CGO_LDFLAGS environment variables are added
48 to the flags derived from these directives. Package-specific flags should 48 to the flags derived from these directives. Package-specific flags should
49 be set using the directives, not the environment variables, so that builds 49 be set using the directives, not the environment variables, so that builds
50 work in unmodified environments. 50 work in unmodified environments.
51 51
52 Within the Go file, C identifiers or field names that are keywords in Go 52 Within the Go file, C identifiers or field names that are keywords in Go
53 can be accessed by prefixing them with an underscore: if x points at a C 53 can be accessed by prefixing them with an underscore: if x points at a C
54 struct with a field named "type", x._type accesses the field. 54 struct with a field named "type", x._type accesses the field.
55 55
56 The standard C numeric types are available under the names 56 The standard C numeric types are available under the names
57 C.char, C.schar (signed char), C.uchar (unsigned char), 57 C.char, C.schar (signed char), C.uchar (unsigned char),
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 to avoid conflicts), write the go.o file to that directory, and invoke 623 to avoid conflicts), write the go.o file to that directory, and invoke
624 the host linker. The default value for the host linker is $CC, split 624 the host linker. The default value for the host linker is $CC, split
625 into fields, or else "gcc". The specific host linker command line can 625 into fields, or else "gcc". The specific host linker command line can
626 be overridden using a command line flag: 6l -hostld='gcc -ggdb' 626 be overridden using a command line flag: 6l -hostld='gcc -ggdb'
627 627
628 These defaults mean that Go-aware build systems can ignore the linking 628 These defaults mean that Go-aware build systems can ignore the linking
629 changes and keep running plain '6l' and get reasonable results, but 629 changes and keep running plain '6l' and get reasonable results, but
630 they can also control the linking details if desired. 630 they can also control the linking details if desired.
631 631
632 */ 632 */
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b