在“开始构建”之前设置环境变量

Starting go1.10 only a safelist of compiler/linker options is allowed. Any options outside these need to be included in an environment variable e.g. ubuntu#echo $CGO_LDFLAGS_ALLOW -Wl,-Bdynamic,--wrap=memcpy More info: https://github.com/golang/go/wiki/InvalidFlag

Inside directory foo I have some go code which imports a package from another directory bar. This bar directory has some cgo code where #cgo flags are declared.

From foo when I do "go build", it goes to bar and does a "go build" which fails as CGO_LDFLAGS_ALLOW is not set in environment.

I want to not have all my team set this env variable explicitly in their environment. Is there a way the environment variable can be set just before "go build" in directory bar?

I tried setting the environment variable in Makefile of foo, but the problem is there are many makefiles in sub directories which may try to build bar. I don't want to set the variable in all makefiles.

So the method I chose is:

create a new file e.g. Makefilevars in foo directory which has this export: export CGO_LDFLAGS_ALLOW -Wl,-Bdynamic,--wrap=memcpy This file is included in all the makefiles which need to build bar.