Go问答 在windows上为 golang二进制程序添加一个图标

codinghxl · 2018年03月14日 · 最后由 crazyvv 回复于 2018年03月14日 · 807 次阅读

在 windows 上为 golang 二进制程序添加一个图标

更多原创文章干货分享,请关注公众号
  • 加微信实战群请加微信(注明:实战群):gocnio

how-do-you-set-the-application-icon-in-golang

The topic is long time, in fact mingw is only requirement, we don't need 3rd party dependency. In addition, resource file *.rc is mandatory for win32 executable application. At last, you can find the demo in rc-demo

1) Install mingw using Chocolatey: choco install mingw

2) Create main.exe.manifest file

<?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" /> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="" publicKeyToken="6595b64144ccf1df" language="" /> </dependentAssembly> </dependency> </assembly> 3) Create main.rc file

100 ICON "main.ico" 100 24 "main.exe.manifest" 101 RCDATA "content.zip" 4) Build

In git-bash windows perform the following command: windres -o main-res.syso main.rc && go build -i

有时候啊,多用搜索引擎搜一下就出来了,比到论坛等答案要快要方便,还能学到关联的知识。

看一下这个工具 https://github.com/akavel/rsrc

Tool for embedding .ico & manifest resources in Go programs for Windows.

2) Create main.exe.manifest file

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
&lt;assembly xmlns=&quot;urn:schemas-microsoft-com:asm.v1&quot; manifestVersion=&quot;1.0&quot;&gt;
&lt;assemblyIdentity
    version=&quot;1.0.0.0&quot;
    processorArchitecture=&quot;x86&quot;
    name=&quot;controls&quot;
    type=&quot;win32&quot;
&gt;&lt;/assemblyIdentity&gt;
&lt;dependency&gt;
    &lt;dependentAssembly&gt;
        &lt;assemblyIdentity
            type=&quot;win32&quot;
            name=&quot;Microsoft.Windows.Common-Controls&quot;
            version=&quot;6.0.0.0&quot;
            processorArchitecture=&quot;*&quot;
            publicKeyToken=&quot;6595b64144ccf1df&quot;
            language=&quot;*&quot;
        &gt;&lt;/assemblyIdentity&gt;
    &lt;/dependentAssembly&gt;
&lt;/dependency&gt;
&lt;/assembly&gt;

3) Create main.rc file

100 ICON    &quot;main.ico&quot;
100 24      &quot;main.exe.manifest&quot;
101 RCDATA  &quot;content.zip&quot;

4) Build In git-bash windows perform the following command: > windres -o main-res.syso main.rc && go build -i

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册