duanliang1898
2014-09-01 09:20
浏览 476
已采纳

如何在golang中设置应用程序图标?

I've just created my first go application on Windows.

How do I give it an icon?

There doesn't seem to be any build flags to do this, and I know golang doesn't support resources.

图片转代码服务由CSDN问答提供 功能建议

我刚刚在Windows上创建了我的第一个go应​​用程序。

如何 我要给它一个图标吗?

似乎没有任何构建标志可以做到这一点,而且我知道golang不支持资源。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • douyuai8994 2014-09-01 11:29
    已采纳

    You can use a tool like akavel/rsrc in order to generate a .syso file with specified resources embedded in .rsrc section, aimed for consumption by Go linker when building Win32 excecutables.

    See as an example the lxn/walk application, which embeds other metadata in its executable.

    rsrc [-manifest FILE.exe.manifest] [-ico FILE.ico[,FILE2.ico...]] -o FILE.syso
    

    -ico="": comma-separated list of paths to .ico files to embed


    This differs from embedding binary data into a go program.
    For that, use jteeuwen/go-bindata.

    To access asset data, we use the Asset(string) []byte function which is included in the generated output.

    data := Asset("pub/style/foo.css")
    if len(data) == 0 {
        // Asset was not found.
    }
    
    // use asset data
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • doulao1966 2017-06-22 01:12

    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

    评论
    解决 无用
    打赏 举报
  • douhan6738 2018-03-06 09:54

    There is a github package GoVersionInfo by Joseph Spurrier:

    Microsoft Windows File Properties/Version Info and Icon Resource Generator for the Go Language

    Package creates a syso file which contains Microsoft Windows Version Information and an optional icon. When you run "go build", Go will embed the version information and an optional icon and an optional manifest in the executable. Go will automatically use the syso file if it's in the same directory as the main() function.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题