关于go build ./文件压缩的步骤
首先需要在build的时候加上参数
//这样就能使项目降低
go build -ldflags '-w -s' ./
如果还需要更小,则需要安装upx
安装完成后配置到系统环境变量中。cmd运行upx
C:\Users\pan>upx
Ultimate Packer for eXecutables Copyright (C) 1996 - 2020 UPX 3.96w Markus Oberhumer, Laszlo Molnar & John Reiser Jan 23rd 2020
Usage: upx [-123456789dlthVL] [-qvfk] [-o file] file..
Commands:
-1 compress faster -9 compress better
-d decompress -l list compressed file
-t test compressed file -V display version number
-h give more help -L display software license
Options:
-q be quiet -v be verbose
-oFILE write output to 'FILE'
-f force compression of suspicious files
-k keep backup files
file.. executables to (de)compress
Type 'upx --help' for more detailed help.
UPX comes with ABSOLUTELY NO WARRANTY; for details visit https://upx.github.io
然后执行upx
需要压缩的exe
文件或linux
文件(upx
兼容多系统)
upx XXX.exe
需要给go exe加图标
创建一个XXX.rc
文件 内容为IDI_ICON1 ICON "XXX.ico"
使用windres.exe生成syso文件
windres -o XXX.syso XXX.rc
然后再go build ./