使用Qt绑定创建静态的Go可执行文件。

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

Static Go executable using Qt binding

问题

基本上,我使用Go编写了一个程序,并使用Qt GUI库的绑定(github.com/bluszcz/cutego)。我转向了cutego分支,因为原始的绑定(github.com/therecipe/qt)不再维护。

我的应用程序运行得很好,但我需要在一个不需要安装任何东西的机器上运行它。我对Go还不太熟悉,请原谅我的无知。我按照这里的说明构建了一个静态可执行文件:(https://github.com/therecipe/qt/wiki/Deploying-Windows-to-Windows-64-bit-Static)

我收到了一些已弃用代码的警告,但代码确实编译通过了。问题是我最终仍然得到一个动态编译的可执行文件。我使用MINGW64运行了ldd,结果如下:

Qt5Core.dll => 未找到
Qt5Gui.dll => 未找到
Qt5Widgets.dll => 未找到

正如我之前提到的,我对Go还不太熟悉,而且对这种语言也很陌生,因为我只使用Python和VBA进行开发。我在网上没有找到任何线索,我认为这是因为有些非常明显的东西我漏掉了,而其他人都已经知道了。

我在这里漏掉了什么?非常感谢任何帮助!

我希望我的可执行文件是静态类型的,这样就不需要安装Qt了。

英文:

Basically, I wrote a program using Go and the binding for the Qt gui library (github.com/bluszcz/cutego). I moved over to the cutego fork because the original binding (github.com/therecipe/qt) isn't being maintained anymore.

My app works great but I need it to run on a machine that needs nothing installed. I'm new to Go so please forgive my ignorance. I followed the instructions to build a static executable here: (https://github.com/therecipe/qt/wiki/Deploying-Windows-to-Windows-64-bit-Static)

I get a few deprecated code warnings but the code does compile. The problem is I still end up with a dynamically compiled executable. I ran ldd using MINGW64 and I get:
> Qt5Core.dll => not found
> Qt5Gui.dll => not found
> Qt5Widgets.dll => not found

As mentioned I am pretty new to Go, but I am also new to this kind of language as I have only developed using Python and VBA. I haven't found any clues online, I think because there's something really obvious that I am missing that everyone else knows about already.

What am I missing here? Any help would be most appreciated!

I would like my executable to be statically typed so that it can run without Qt installed.

答案1

得分: 0

当你使用cgo时,你的Go可执行文件将在运行时链接到共享库,具体取决于cgo代码引用的C库。

如果你希望使用cgo并拥有一个独立的可执行文件,你需要将你的二进制文件链接到静态库(通常是.a文件)。不过,提供这些库是第三方模块的责任,而qt可能不会默认提供这些库。

英文:

When you use cgo, your go executable will link to shared libraries at run time depending on what C libraries the cgo code references.

If you wish to use cgo and have a stand alone executable you need to link your binary to static libraries (typically .a files). It is up to the third party module to provide such libraries, though, and qt may not provide them out of the box.

答案2

得分: 0

我找到了问题。所以在github.com/therecipe/qt上有两种安装选项。你可以选择正常默认的方式安装,也可以选择使用“静态”方法安装。如果两种方式都使用,可能会出现问题。我最后删除了与github.com/therecipe/qt相关的所有文件。然后只使用静态的Windows x64到Windows x64方法进行安装,并按照那些部署静态可执行文件的说明进行操作。按照MYSYS2的说明进行操作,一切都很顺利。

英文:

I found the problem. So with github.com/therecipe/qt you have 2 install options. You can either install the normal default way or you can install using the "static" method. You'll have problems if you do both. I ended up removing all files relative to github.com/therecipe/qt. I then installed using the static Windows x64 to Windows x64 method ONLY and followed those instructions for deploying a static executable. Worked like a charm using the instructions for MYSYS2.

huangapple
  • 本文由 发表于 2023年2月6日 04:22:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/75355271.html
匿名

发表评论

匿名网友

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

确定