go 语言打包编译

2021/12/14 GO 共 617 字,约 2 分钟

go 语言打包编译

缩减 Golang 编译后文件大小的三种方法

https://zhuanlan.zhihu.com/p/313053187

使用 upx 减小体积

upx 安装

UPX is an advanced executable file compressor. UPX will typically reduce the file size of programs and DLLs by around 50%-70%, thus reducing disk space, network load times, download ti mes and other distribution and storage costs.

upx 是一个常用的压缩动态库和可执行文件的工具,通常可减少 50-70% 的体积。

upx 的安装方式非常简单,我们可以直接从 github 下载最新的 release 版本,支持 Windows 和 Linux,在 Ubuntu 或 Mac 可以直接使用包管理工具安装。例如 Mac 下可以直接使用 brew:

$ sudo apt-get install upx


$ go build -o server| upx -9 server
        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
  22663989 ->  11407128   50.33%   linux/amd64   server

$ ll -h
-rwxrwxr-x  1 lzm lzm  11M 2月   3 16:14 server*

文档信息

Search

    Table of Contents