I am trying to execute cgo code under ubuntu 14.04, it seems like cgo assume CC/CXX
to be gcc/g++
. And I need to explicitly specify CC/CXX
in order to use, say, clang. Can I configure default compiler used through go's build constraints?
Thanks!
If you're using the go
command to build the code, then the CC_FOR_TARGET
environment variable determines where go
looks for the C compiler.
e.g. env CGO_ENABLED=1 CC_FOR_TARGET=/path/to/compiler go build foo.go
It doesn't look like it's possible to specify the compiler using build constraints, though it is somewhat possible to specify CFLAGS. See the docs below for details.
Reference: https://golang.org/cmd/cgo/#hdr-Using_cgo_with_the_go_command