将动态库链接到链接到其他静态库的静态库 [英] Linking a dynamic library to a static library that links to other static libraries

查看:270
本文介绍了将动态库链接到链接到其他静态库的静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的C ++应用程序中有一个静态库(libCOMMON.a),它链接到boost库:system,filsystem,timer和chrono。

In my C++ application I have a static library (libCOMMON.a) that links to boost libraries: system, filsystem, timer and chrono.

这里是我如何创建和链接libCOMMON.a:

I am using CMake and here is how I create and link libCOMMON.a:

ADD_LIBRARY(COMMON ${COMMON_SRCS})
target_link_libraries(COMMON 
    ${BOOST_LIB_DIR}/libboost_filesystem.a
    ${BOOST_LIB_DIR}/libboost_system.a
    ${BOOST_LIB_DIR}/libboost_timer.a
    ${BOOST_LIB_DIR}/libboost_chrono.a
)



我也有这个应用程序的链接到libCOMMON.a的插件。这些插件构建为动态库。一切编译确定(使用gcc),但是当我启动应用程序,插件无法加载,因为与boost相关的动态库中的一些符号无法解决。

I also have plugins for this application that links to libCOMMON.a. The plugins are built as dynamic libraries. Everything compiles ok (using gcc) but when I start the application, the plugins can't be loaded because some symbols in the dynamic libraries related to boost cannot be resolved.

解决方案是链接每个插件boost。有更好的方法吗?
我认为如果boost库静态链接到libCOMMON.a,就足以将插件链接到libCOMMON.a。

The solution was to link each of the plugins to boost. Is there a better way ? I thought that if boost libraries are linked statically into libCOMMON.a, it would be enough to link the plugins to libCOMMON.a.

有人可以解释什么

感谢

推荐答案

默认情况下,库被构建为动态库。即使.a表明它们构建为静态库,boost的lib文件夹也包含每个.a的.so库。这意味着libCOMMON.a被动态链接到boost库。因此,静态链接到libCOMMON.a的插件也必须动态链接到boost库。更好的解决方案是将boost库构建为静态库。

I think the problem is that boost libraries are built as dynamic libraries by default. Even if the ".a" suggests that they are built as static libraries, the lib folder of boost contains a ".so" library with each ".a". Which means that libCOMMON.a is linked dynamically to boost libraries. For this reason, the plugins that statically links to libCOMMON.a has also to dynamically link to boost libraries. A better solution would be to build boost libraries as static libraries.

这篇关于将动态库链接到链接到其他静态库的静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆