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!
The C or C++ compiler used by cgo
can be specified using the CC
and CXX
environment variables respectively. For example, to use Clang:
CC=clang go build path/to/cgo/dependent/code.go
The variables can also specify flags to be passed to the compilers; for example, to run GCC with optimizations:
CC="gcc -O2" go build path/to/cgo/dependent/code.go
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With