golang开发windows应用添加图标

开源工具源码地址:github.com/akavel/rsrc

  • 下载rsrc工具
  • 创建一个manifest文件
1
2
3
4
5
6
7
8
9
<?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="Amd64" name="controls" type="win32"></assemblyIdentity>
<dependency>
    <dependentAssembly>
        <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="Amd64" publicKeyToken="6595b64144ccf1df" language="*"></assemblyIdentity>
    </dependentAssembly>
</dependency>
</assembly>
  • windows下生成syso文件
1
rsrc_windows_amd64.exe -manifest manifest -ico inventory.ico -arch amd64 -o inventory.syso
  • 构建
1
GOOS=windows CGO_ENABLED=1 GOARCH=amd64 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build -ldflags '-w -s' .

注意,网上找到的资料都会报以下的错:

[阅读全文]