Skip to content

Reduce binary file size in Golang

Golang减小编译后二进制体积

编译参数

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

upx

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.