Arbitrary ldflags may not make sense, but if you merely want to ensure main.go produces a static binary, then it absolutely makes sense. I was asking about this on Twitter earlier: https://twitter.com/mikedoherty_ca/status/796570476462112768
What would you think of a restricted feature that merely controlled static-ness, and can only be used from package main/main.go? -Mike On Wednesday, December 2, 2015 at 5:18:23 PM UTC-8, Ian Lance Taylor wrote: > > On Wed, Dec 2, 2015 at 4:24 PM, Tim K <tim....@gmail.com <javascript:>> > wrote: > > > > Thank you. Should an issue be opened for adding #cgo support for -static > or > > is this already being tracked. > > As far as I know it is not already being tracked. But, thinking about > it, I'm not sure it makes sense. #cgo LDFLAGS is useful for adding > libraries. Doing anything else is dubious. If we had some sort of > FINAL_LDFLAGS, then it would be straightforward for different packages > to request FINAL_LDFLAGS that conflicted. Setting the flags from `go > build`, which already works, seems more correct and safer. > > Ian > > > > On Wednesday, December 2, 2015 at 4:21:58 PM UTC-8, Ian Lance Taylor > wrote: > >> > >> On Wed, Dec 2, 2015 at 2:23 PM, Tim K <tim....@gmail.com> wrote: > >> > As in: > >> > > >> > // #cgo LDFLAGS: -static > >> > > >> > It doesn't seem to work, I get an error, but maybe I'm doing > something > >> > wrong: > >> > > >> > cannot load imported symbols from ELF file > >> > $WORK/command-line-arguments/_obj/_cgo_.o: no symbol section > >> > >> No, it won't work. The -static option will be used while cgo is doing > >> its magic, and, as you see, it will cause that magic to break. We > >> would need something new, #cgo FINAL_LDFLAGS or something, for linker > >> flags to only use on the final link. > >> > >> > If it is actually possible to specify static linking via #cgo, can it > be > >> > made conditional based on where it's compiled, e.g. static on > >> > linux/amd64 > >> > but dynamic on darwin (where static doesn't work)? > >> > >> If it could be done, then, yes, this could be done. The #cgo line > >> takes optional build constraints. > >> > >> Ian > > > > -- > > You received this message because you are subscribed to the Google > Groups > > "golang-nuts" group. > > To unsubscribe from this group and stop receiving emails from it, send > an > > email to golang-nuts...@googlegroups.com <javascript:>. > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.