目前只测试了windows,linux不知道行不行,我linux也没有桌面的
因为默认的go build -o xxx.exe这样是没有图标的,不怎么好看。
首先下载文件:
git clone https://github.com/akavel/rsrc.git
进入目录,把上面的代码编译一下
go build rsrc.go 然后有个rsrc.exe文件
就在rsrc的目录下创建个ico.manifest,内容如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="x86"
name="controls"
type="win32"
></assemblyIdentity>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
></assemblyIdentity>
</dependentAssembly>
</dependency>
</assembly>
然后把你想要编译带上的ico文件复制到rsrc文件夹,例如 rc.ico
执行命令生成:xxx.syso文件
rsrc.exe -manifest ico.manifest -ico rc.ico -o xxx.syso
把xxx.syso文件复制到你要编译的项目
执行编译 go build -o main.exe 正常编译即可
在这里编译需要注意的是:
1.不能指定编译某个go文件如:go build -o main.exe main.go 这样是不会带上图标的,直接这样编译 go build -o main.exe
2.如下图所示,我的go项目除了main.go还有tt.go,需要把tt.go改下名字,改成除了.go即可,还有我这里生成了很多个syso文件,保留一个你需要用的syso文件,其他的都改掉后缀