Go 添加图标,管理员权限执行后,编译报错

安装rsrc

go get github.com/akavel/rsrc

创建manifest文件

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
        <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
            <security>
                <requestedPrivileges>
                    <requestedExecutionLevel level="requireAdministrator"/>
                </requestedPrivileges>
            </security>
    </trustInfo>
</assembly>

生成syso文件

rsrc -manifest rsrc.manifest -ico icon.ico -o rsrc.syso
go build -ldflags "-s -w" -o myapp.exe  // 以目录方式进行编译

两个程序都成功了,但有一个程序编译时报错,好像说架构不同
... i386 architecture of input file 'rsrc.syso' is incompatible with i386:x86-64 out

网上找到的一些方案是编译时加标签:

-ldflags "-linkmode internal"

但在我这里无效,没有解决

然后看到 rsrc 的 help … 生成 syso 时架构设置成 amd64,再编译就没问题了

USAGE:
C:\Users\ANDY\go\bin\rsrc.exe [-manifest FILE.exe.manifest] [-ico FILE.ico[,FILE2.ico...]] -o FILE.syso
  Generates a .syso file with specified resources embedded in .rsrc section,
  aimed for consumption by Go linker when building Win32 excecutables.
The generated *.syso files should get automatically recognized by 'go build'
command and linked into an executable/library, as long as there are any *.go
files in the same directory.

OPTIONS:
  -arch string
        architecture of output file - one of: 386, amd64, [EXPERIMENTAL: arm, arm64] (default "386")
  -data string
        path to raw data file to embed [WARNING: useless for Go 1.4+]
  -ico string
        comma-separated list of paths to .ico files to embed
  -manifest string
        path to a Windows manifest file to embed
  -o string
        name of output COFF (.res or .syso) file (default "rsrc.syso")
rsrc -arch amd64 -manifest rsrc.manifest -ico icon.ico -o rsrc.syso
go build -ldflags "-s -w" -o myapp.exe
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值