Skip to content

Commit dc4dd57

Browse files
cmd/cgo: document how CGO_ENABLED works today
Fixes #9530. Change-Id: Iadfc027c7164e3ba35adb5c67deb42b51d3498ca Reviewed-on: https://go-review.googlesource.com/12603 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Dave Cheney <dave@cheney.net>
1 parent e3ba097 commit dc4dd57

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/cmd/cgo/doc.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,19 @@ compilers may be changed by the CC and CXX environment variables,
9090
respectively; those environment variables may include command line
9191
options.
9292
93-
To enable cgo during cross compiling builds, set the CGO_ENABLED
94-
environment variable to 1 when building the Go tools with make.bash.
95-
Also, set CC_FOR_TARGET to the C cross compiler for the target. CC will
96-
be used for compiling for the host.
97-
98-
After the Go tools are built, when running the go command, CC_FOR_TARGET is
99-
ignored. The value of CC_FOR_TARGET when running make.bash is the default
100-
compiler. However, you can set the environment variable CC, not CC_FOR_TARGET,
101-
to control the compiler when running the go tool.
102-
103-
CXX_FOR_TARGET works in a similar way for C++ code.
93+
The cgo tool is enabled by default for native builds on systems where
94+
it is expected to work. It is disabled by default when
95+
cross-compiling. You can control this by setting the CGO_ENABLED
96+
environment variable when running the go tool: set it to 1 to enable
97+
the use of cgo, and to 0 to disable it. The go tool will set the
98+
build constraint "cgo" if cgo is enabled.
99+
100+
When cross-compiling, you must specify a C cross-compiler for cgo to
101+
use. You can do this by setting the CC_FOR_TARGET environment
102+
variable when building the toolchain using make.bash, or by setting
103+
the CC environment variable any time you run the go tool. The
104+
CXX_FOR_TARGET and CXX environment variables work in a similar way for
105+
C++ code.
104106
105107
Go references to C
106108

0 commit comments

Comments
 (0)