0

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.

  • There's no magic way to do this. You need to use a script, or a Makefile, as you said. Getting it to work in your specific configuration means coming up with a solution that fits your exact requirements, but your requirements are complex enough that I don't think we can just hand you a solution. You'll have to experiment and apply your debugging skills until you find a solution that works. – Jonathan Hall Jul 18 '19 at 06:57

1 Answers1

0

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.