The way to make the Go program smaller

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. go Build-ldflags "-s-w" (go install similar)

explain the meaning of the parameter:
-ldflags: Indicates that the following parameters are passed to the connector (5/6/8l)
- S: Remove the symbol information (and then panic when the stack trace does not have any file name/line number information, which is equivalent to the general C/s program is strip effect)
-W: Removes dwarf debug information. The resulting program cannot be debugged with GDB.

The following Demo.go
[AppleScript] Plain Text View Copy Code
12345 package main import (" FMT ") func main () {      fmt. Print (" hellow! ") }

E:\go Build Demo.go//compiled for 1163 K
E:\go build-ldflags "-s-w" demo.go//compiled for 591K

-S and-W can also be used separately, generally if you do not intend to debug with GDB,-W basically no loss.
the loss of-S is a bit big.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.