Skip to content

Commit cbfda7f

Browse files
ikkerensianlancetaylor
authored andcommitted
cmd/cgo: clarify implicit "cgo" build constraint
When using the special import "C", the "cgo" build constraint is implied for the go file, potentially triggering unclear "undefined" error messages. Explicitly explain this in the documentation. Updates #24068 Change-Id: Ib656ceccd52c749ffe7fb2d3db9ac144f17abb32 GitHub-Last-Rev: 5a13f00 GitHub-Pull-Request: #24072 Reviewed-on: https://go-review.googlesource.com/96655 Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 515fa58 commit cbfda7f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/cmd/cgo/doc.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ it is expected to work. It is disabled by default when
109109
cross-compiling. You can control this by setting the CGO_ENABLED
110110
environment variable when running the go tool: set it to 1 to enable
111111
the use of cgo, and to 0 to disable it. The go tool will set the
112-
build constraint "cgo" if cgo is enabled.
112+
build constraint "cgo" if cgo is enabled. The special import "C"
113+
implies the "cgo" build constraint, as though the file also said
114+
"// +build cgo". Therefore, if cgo is disabled, files that import
115+
"C" will not be built by the go tool. (For more about build constraints
116+
see https://golang.org/pkg/go/build/#hdr-Build_Constraints).
113117
114118
When cross-compiling, you must specify a C cross-compiler for cgo to
115119
use. You can do this by setting the generic CC_FOR_TARGET or the

0 commit comments

Comments
 (0)