安装rsrc
- 点击下载rsrc
- 生成rsrc.exe 可执行文件,前提是已经安装了go语言环境
cd .\rsrc-master\ go build # 同目录下生成了 rsrc.exe 文件,移动 rsrc.exe 到你的GO安装目录的bin子目录下面, 如 C:\Program Files\Go\bin\rsrc.exe
打包程序图标并去除黑窗口
- 项目目录结构
E:\CODE\TEST\GO\GTPBOT
│ config.dev.json
│ config.pro.json
│ go.mod
│ go.sum
│ main.go
│ storage.json
│
├─bootstrap
│ bootstrap.go
│
├─config
│ config.go
│
├─gtp
│ gtp.go
│
├─handles
│ handle.go
│ msg_handler.go
│
└─resource
icon.ico
info.manifest
- info.manifest 内容
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="SomeFunkyNameHere" type="win32"/>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
</dependentAssembly>
</dependency>
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
main.go 文件
//go:generate rsrc -ico resource/icon.ico -manifest resource/info.manifest -o main.syso package main import ( "gtpbot/bootstrap" ) func main() { bootstrap.Run() }
生成
- -ldflags="-linkmode internal" 通过Directory的方式编译,编译器会自动寻找同目录下的资源文件并打包进EXE
-ldflags="-H windowsgui" 取消黑窗口
go generate # 命令生成 main.syso资源文件 go build -o mybot.exe -ldflags="-linkmode internal" -ldflags="-H windowsgui"
Comment here is closed