FAQ
I (almost) always compile my tools with -ldflags "-s" to reduce the size of
the binaries.

Is there a way to define the -ldflags globally, like in an environment
variable or a config file in $GOROOT or as a structured comment in the
source?

Thanks
Stefan

PS. Couldn't find anything in the usual places.


--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Minux at Apr 1, 2014 at 3:52 pm

    On Tue, Apr 1, 2014 at 11:07 AM, Ondekoza wrote:

    I (almost) always compile my tools with -ldflags "-s" to reduce the size
    of the binaries.
    Is there a way to define the -ldflags globally, like in an environment
    variable or a config file in $GOROOT or as a structured comment in the
    source?
    No, there isn't a way to set it globally (except modifying the source code
    for cmd/go or cmd/ld or
    making your own go command alias/wrapper)
    PS. Couldn't find anything in the usual places.
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Dave Cheney at Apr 1, 2014 at 7:31 pm
    -ldflags -s doesn't do what you think it does. Specifically that option was
    neutered because strip(1)ing go binaries doesn't make them smaller and
    often leaves them non functional
    On Wednesday, 2 April 2014 02:07:19 UTC+11, Ondekoza wrote:

    I (almost) always compile my tools with -ldflags "-s" to reduce the size
    of the binaries.

    Is there a way to define the -ldflags globally, like in an environment
    variable or a config file in $GOROOT or as a structured comment in the
    source?

    Thanks
    Stefan

    PS. Couldn't find anything in the usual places.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Gustavo Niemeyer at Apr 1, 2014 at 7:54 pm

    On Tue, Apr 1, 2014 at 4:31 PM, Dave Cheney wrote:
    -ldflags -s doesn't do what you think it does. Specifically that option was
    neutered because strip(1)ing go binaries doesn't make them smaller and often
    leaves them non functional
    It did make the binary significantly smaller whenever I tried it, and
    I had a single case where the binary did break. The QML+OpenGL gopher
    example goes from 7.7MB to 2.9MB, for example, and spins happily.

    That's not to say someone should trust it to work, though. Nobody is
    testing this.


    gustavo @ http://niemeyer.net

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Dave Cheney at Apr 1, 2014 at 7:56 pm

    That's not to say someone should trust it to work, though. Nobody is
    testing this.
    Precisely. It can make your binaries smaller, and it can also make
    them not work. Stripped binaries are not tested as part of CI or
    during the release builds, and bugs previously raised about this have
    generally (not always) been closed with a recommendation not to do
    that.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Gustavo Niemeyer at Apr 1, 2014 at 8:52 pm
    Yes, but "because strip(1)ing go binaries doesn't make them smaller"
    is not even close to being true. Even a "Hello world" example
    including fmt is dramatically reduced in size by strip. Rather than
    denying it, we should take that into account for
    http://golang.org/issue/6853 (which is a good issue to star for those
    interested in binary size matters).




    On Tue, Apr 1, 2014 at 4:56 PM, Dave Cheney wrote:
    That's not to say someone should trust it to work, though. Nobody is
    testing this.
    Precisely. It can make your binaries smaller, and it can also make
    them not work. Stripped binaries are not tested as part of CI or
    during the release builds, and bugs previously raised about this have
    generally (not always) been closed with a recommendation not to do
    that.


    --

    gustavo @ http://niemeyer.net

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 1, '14 at 3:07p
activeApr 1, '14 at 8:52p
posts6
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase