Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I change default compiler used by cgo?

Tags:

go

cgo

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!

like image 409
Xiaoqin Zhu Avatar asked Jun 30 '17 23:06

Xiaoqin Zhu


1 Answers

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
like image 102
James Fennell Avatar answered Nov 10 '22 00:11

James Fennell