资源中的链接

huangapple go评论78阅读模式
英文:

Link in resources

问题

看起来在网上和SO上有很多网页和问题,但是经过几个小时的搜索后,我仍然无法使其工作。

我正在从Linux交叉编译到Windows,通过将CC/CXX设置为x86-64 MinGW-w64。编译实际上是成功的,并且在Windows上运行的exe文件也正常。

使用file命令,我得到以下输出:

PE32+ executable (GUI) x86-64 (stripped to external PDB), for MS Windows

我有两个资源文件(一个Windows的*.ico文件和一个包含VERSIONINFO等属性的*.res ASCII文件)。

使用MinGW的windres工具,这两个资源文件被转换为*.o文件。它们现在看起来像COFF文件。这是我能做到的最远的地方。

我想要做的是将这两个资源链接到exe文件中。

我找不到任何方法来指示Go链接器在链接过程中包含这些文件(我运行的是go build,而不是go tool)。我还尝试过在链接后使用objcopy根据网上的各种页面和其他SO问题来添加资源,但是都没有成功。

我只是希望Windows能够识别这两个资源(图标和信息),使得可执行文件在Windows上的行为与其他任何可执行文件相同。

如果我应该指示Go链接器(而不是go build)使用go tool,那么我如何告诉它要链接哪些文件?我有一些“简单”的*.go文件,然后是我使用CGO链接的C依赖项(GLFW和OpenGL)。

如何在Linux命令行上完成这个过程?我想将这些步骤添加到更广泛的CI/CD(构建工作流程/资产管道)中。Windows的GUI工具或类似工具对我帮助不大。

谢谢!

英文:

Looks like there are tons of webpages online and questions on SO, but I still can't get this to work after several hours of searching.

I'm cross-compiling from Linux to Windows by setting CC/CXX to x86-64 MinGW-w64. Compilation actually works and the exe runs fine on Windows.

With file I get this output:

PE32+ executable (GUI) x86-64 (stripped to external PDB), for MS Windows

I have two resource files (a Windows *.ico file and a *.res ASCII file that contains properties such as VERSIONINFO and the like).

The two resource files are transformed into *.o files with MinGW's windres tool. They look like COFF files now. That's as far as I could get.

What I want to do is link those two resources into the exe.

I don't find any way to instruct the Go linker to include those files during linking (I run go build, not go tool). I've also tried to add the resource post-linking with objcopy following various pages online and other SO questions... but to no avail.

All I want is Windows to recognize those two resources (icon and info) so that the executable behaves like any other on Windows.

If I should instruct the Go linker (go tool instead of go build), then how can I tell it which files to link? I have "simple" *.go files and then C dependencies (GLFW and OpenGL) I link with CGO.

How can this be done on the Linux command-line? I want to add these steps to a broader CI/CD (build workflow/asset pipeline). A Windows GUI tool or similar would not help much.

Thanks!

答案1

得分: 2

我不知道你是否正在使用Fyne,但是你提到的“fyne package”听起来像是嵌入图标和元数据的功能。

如果你正在使用Fyne,你可以使用他们的工具。如果不是的话,可以查看源代码,亲自了解它是如何实现的。你可以在这里找到源代码:https://github.com/fyne-io/fyne/blob/master/cmd/fyne/internal/commands/package-windows.go

英文:

I don’t know if you are using Fyne, but it sounds like what “fyne package” does (embed icon and metadata).

If you are in Fyne land then you can use their tools, if not maybe check out the source and see for yourself how it’s done? https://github.com/fyne-io/fyne/blob/master/cmd/fyne/internal/commands/package-windows.go

huangapple
  • 本文由 发表于 2023年1月19日 23:01:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75174226.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定