简体   繁体   English

将静态Qt库链接到c程序

[英]Link static Qt library to c program

I am in the need to link against a library (written in Qt by myself). 我需要链接到一个库(我自己用Qt编写)。 Of course this would generate (regardless of the extern "C" and name mangling stuff) a lot of errors during linking because of the C++ dependencies (stdc++ and Qt). 当然,由于C ++依赖关系(stdc ++ Qt),这将产生(无论extern "C"和名称修改的东西)链接期间的大量错误。

So I have got an idea, but I'm not sure, if I am missing something or if the approach is a realistic solution at all: 所以我有一个想法,但我不确定,如果我遗漏了某些东西,或者这种方法是否是一个现实的解决方案:

Searching some hints on this topic, I have found an article about building static Qt . 搜索关于此主题的一些提示,我发现了一篇关于构建静态Qt的文章。 Without reading all of it in detail I think the solution could be to compile Qt statically and then link my application against this static version of Qt. 在没有详细阅读所有内容的情况下,我认为解决方案可能是静态编译Qt,然后将我的应用程序与Qt的静态版本链接起来。 In my opinion this should lead to a successful build because of the following reasons: 在我看来,这应该导致成功构建,原因如下:

  1. Building my Qt library with the static Qt Library (again as static lib) would resolve all dependencies because they are all in the static lib archive. 使用静态Qt库(再次作为静态库)构建我的Qt库将解析所有依赖项,因为它们都在静态库存档中。

  2. Because of the extern "C" d interface functions, that will be accessed by the c application the C compiler (and linker) will also see all dependencies resolved and here is no problem either. 由于extern "C" d接口函数将由c应用程序访问,C编译器(和链接器)也将看到所有依赖项已解决,这里也没有问题。

Now before trying the exhausting steps to build Qt statically, I would like to know, whether this approach could solve the problem. 现在,在尝试静态构建Qt的耗尽步骤之前,我想知道,这种方法是否可以解决问题。

EDIT 1: The alternative solution would be to implement a server-client architecture on top of both the Qt- and the C-part of the application and let them communicate in that way with each other. 编辑1:替代解决方案是在应用程序的Qt和C部分之上实现服务器 - 客户端体系结构,并让它们以这种方式相互通信。

EDIT 2: The probably best solution is neither of the both mentioned. 编辑2:可能最好的解决方案都不是两者都提到的。 Instead I just wrote a dynamically linked boundary (as suggested by Laszlo Papp and dsu) and everything works fine. 相反,我只是写了一个动态链接的边界(由Laszlo Papp和dsu建议),一切正常。

Now before trying the exhausting steps to build Qt statically, I would like to know, whether this approach could solve the problem. 现在,在尝试静态构建Qt的耗尽步骤之前,我想知道,这种方法是否可以解决问题。

Based on the comments where you mention that becoming a commercial client of Digia is a problem, I would say no. 基于你提到成为Digia的商业客户的评论是一个问题,我会说不。

Static linking cannot happen with proprietary software, and based on your comment, your project is not open sourceable. 专有软件不会发生静态链接,根据您的评论,您的项目不可开源。

That being said, you seem to have your own wrapper anyway, and Qt keeps binary compatibility for a given major version the lifecycle of which is usually several years, so I would personally go for dynamic linking and some kind of binding. 话虽这么说,你似乎有自己的包装器,Qt保持二进制兼容性的给定主要版本的生命周期通常是几年,所以我个人会去动态链接和某种绑定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM