如何将 Qt 应用程序编译成静态库?
我的主项目有一个复杂的后端(以及编译过程)。 因此,我不想向该系统介绍构建 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您正在使用 qmake 项目文件 (.pro) 来构建这个库。如果您这样做,只需将 .pro 文件的
TEMPLATE=app
部分替换为: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:简单地说,你不能那样做。
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.