如何将 Qt 应用程序编译成静态库?

发布于 2025-01-06 14:47:33 字数 243 浏览 1 评论 0原文

我的主项目有一个复杂的后端(以及编译过程)。 因此,我不想向该系统介绍构建 Qt Gui 所需的所有额外内容。

因此,我想静态编译 Qt GUI 端,然后在最后添加一些 -lmygui 到我的构建过程中。

注意:这并不是说我希望静态构建所有 Qt 库(这样做会违反 LGPL)。本质上,它应该与我静态构建后端并将其链接到 qt 相同(这将是我的第二个选择,但是一个较差的解决方案)。

我该怎么做?

I have a complicated backend (and compile process as well) to my main project.
Hence, I dont want to introduce all of the extra things that building a Qt Gui requires to that system.

Therefore, I want to compile the Qt GUI side statically and then add a little -lmygui into my build process at the end.

NOTE: This isnt to say that I want all of the Qt libraries to be built statically (doing so would violate the LGPL). Essentially, it should be the same as if i build the backend statically and linked that into qt (which would be my second option, but is an inferior solution).

How do I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北恋 2025-01-13 14:47:33

我假设您正在使用 qmake 项目文件 (.pro) 来构建这个库。如果您这样做,只需将 .pro 文件的 TEMPLATE=app 部分替换为:

TEMPLATE=lib
CONFIG+=staticlib

I'm going to assume that you are using qmake project files (.pro) for building this library. If you're doing it that way, just replace the TEMPLATE=app section of the .pro file with this:

TEMPLATE=lib
CONFIG+=staticlib
焚却相思 2025-01-13 14:47:33

简单地说,你不能那样做。
Qt 需要的不仅仅是 -mygui,如果您在类中使用信号和槽,您还需要运行“moc”可执行文件,它将解析您的 c++ 文件并生成“moc_sources.cxx”文件,该文件也将被编译与你的项目。没有办法在不运行 moc 的情况下直接链接到 qt,并且如果您使用 *.ui 文件作为界面,您还需要运行 uic,这将生成适当的源。

simply, you cant do just that.
Qt requires more than a -mygui, if you use signals and slots in your classes, you will also need to run the 'moc' executable, that will parse your c++ files and generate 'moc_sources.cxx' files, that will also be compiled with your project. there's no way to just link against qt without running moc, and if you use *.ui files for your interface, you will also need to run uic, that will generate the apropriate sources.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文