Skip to content

Reduce binary file size in Golang

减小Golang编译后二进制体积

Compile with parameter

go build -ldflags="-w -s"
参数含义
-w去除DWARF调试信息,会导致panic时,调用堆栈信息没有文件名、行号信息
-s去除符号表信息,无法使用gdb调试

upx tool

https://github.com/upx/upx

upx devapp

Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2020
UPX 3.96        Markus Oberhumer, Laszlo Molnar & John Reiser   Jan 23rd 2020

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
  14229578 ->   7080260   49.76%   linux/amd64   devapp                        

Packed 1 file.

Disclaimer
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback me#imzye.me, replace # with @
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Try my iOS App