2023-06-11  2024-09-18    285 字  1 分钟

默认的go build -o xxx.exe这样是没有图标的,不怎么好看。

首先下载文件:

1git clone  https://github.com/akavel/rsrc.git

进入目录,把上面的代码编译一下

1go build rsrc.go # 然后有个rsrc.exe文件

就在rsrc的目录下创建个ico.manifest,内容如下:

 1<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 2<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
 3<assemblyIdentity
 4    version="1.0.0.0"
 5    processorArchitecture="x86"
 6    name="controls"
 7    type="win32"
 8></assemblyIdentity>
 9<dependency>
10    <dependentAssembly>
11        <assemblyIdentity
12            type="win32"
13            name="Microsoft.Windows.Common-Controls"
14            version="6.0.0.0"
15            processorArchitecture="*"
16            publicKeyToken="6595b64144ccf1df"
17            language="*"
18        ></assemblyIdentity>
19    </dependentAssembly>
20</dependency>
21</assembly>

然后把你想要编译带上的ico文件复制到rsrc文件夹,例如 rc.ico

执行命令生成:xxx.syso文件

1rsrc.exe  -manifest ico.manifest -ico rc.ico -o xxx.syso

把xxx.syso文件复制到你要编译的项目

执行编译 go build -o main.exe 正常编译即可

在这里编译需要注意的是:不能指定编译某个go文件如:go build -o main.exe main.go 这样是不会带上图标的,直接这样编译 go build -o main.exe

除另有声明外本博客文章均采用 知识共享 (Creative Commons) 署名 4.0 国际许可协议 进行许可转载请注明原作者与文章出处