简体   繁体   中英

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.

When generating .pc file for my library should I add all these libraries also to the .pc file as dependencies?

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. 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.

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.

I have just used CMake and link_libraries to add boost and pcl libs.

When generating .pc file for my library should I add all these libraries also to the .pc file as dependencies?

It depends on API of your library:

  • 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;
  • 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 ). For the last case, you also need to add your dependencies to the *.pc files.

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…

I have just used CMake and link_libraries to add boost and pcl libs.

Please read smth about "Modern CMake" and stop using link_libraries :-) -- use target_link_libraries instead…

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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