简体   繁体   English

哪些库应作为依赖项进入pkg-config文件?

[英]Which libraries should go to a pkg-config file as a dependencies?

I'm writing a shared library that itself depends on boost and pcl libraries. 我正在写一个共享库,它本身依赖于boostpcl库。

When generating .pc file for my library should I add all these libraries also to the .pc file as dependencies? 在为我的库生成.pc文件时,是否还应将所有这些库也作为依赖项添加到.pc文件中?

It's been a long time since I last time studied these things and I'm a bit confused how this worked again on Linux. 自从我上次研究这些东西已经很长时间了,我有点困惑它在Linux上又如何工作。 When my test app links to my lib I have to add all these pcl and boost libs again to the build even though the lib already has been linked against these libs. 当我的测试应用程序链接到我的库时,我必须添加所有这些pcl并再次将库boost到构建中,即使该库已经针对这些库进行了链接。

But when I look at the deps of libQtGui.so , for example, it has tens of all kinds of libs it links to, but I don't need to make my app link to those libs...only -lQtGui is enough. 但是,例如,当我查看libQtGui.so ,它具有数十种可链接到的各种库,但是我不需要将我的应用程序链接到那些库...仅-lQtGui就足够了。

I have just used CMake and link_libraries to add boost and pcl libs. 我刚刚使用CMake和link_libraries添加了boostpcl库。

When generating .pc file for my library should I add all these libraries also to the .pc file as dependencies? 在为我的库生成.pc文件时,是否还应将所有这些库也作为依赖项添加到.pc文件中?

It depends on API of your library: 这取决于您的库的API:

  • if public (ie installable) headers of your lib use boost/pcl (ie have #inclue <boost/...> ) (in other words you used PUBLIC (or INTERFACE ) named keywords when link your library against boost/pcl in CMake+ target_link_libraries ) -- then yes you need to add 'em; 如果lib的公共(即可安装)标头使用boost / pcl(即具有#inclue <boost/...> )(换句话说,当您在CMake +中将库链接到boost / pcl时使用了PUBLIC (或INTERFACE )命名的关键字target_link_libraries ) -然后你需要“添加EM;
  • otherwise, it depends on what exactly you have at the end -- ie does your DSO has DT_NEEDED entries for boost/pcl libs (most likely) or not (you can check it w/ ldd <your-lib>.so ). 否则,这取决于您到底拥有什么-即您的DSO是否具有DT_NEEDED条目(最有可能)来获取boost / pcl库(您可以通过w / ldd <your-lib>.so )。 For the last case, you also need to add your dependencies to the *.pc files. 对于最后一种情况,您还需要将依赖项添加到*.pc文件。

Also, in case of binary dependency from boost/pcl (dunno if the latter has any DSO or not) please make sure you specify exact location of the linked libs -- cuz a user may have multiple (co-existed) boost installations (potentially incompatible) or can do upgrade (later) to other (binary incompatible) version (and you can't really do smth w/ it)… It is important to be linked to the same (or at least binary compatible, which is kinda hard to guarantee for boost) library as you did… 另外,如果来自boost / pcl的二进制依赖关系(如果后者没有DSO,则不知道),请确保您指定链接库的确切位置-因为用户可能有多个(共存)boost安装(可能不兼容)或可以升级(后来)到其他(二进制不兼容)版本(而且您无法真正做到这一点)…重要的是要链接到同一版本(或至少与二进制兼容),这有点难保证像您所做的那样提升)库…

I have just used CMake and link_libraries to add boost and pcl libs. 我刚刚使用CMake和link_libraries添加了boost和pcl库。

Please read smth about "Modern CMake" and stop using link_libraries :-) -- use target_link_libraries instead… 请阅读“现代CMake的”水木清华和停止使用link_libraries :-) -使用target_link_libraries ,而不是...

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

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