c++ - 为什么 boost::log 的链接限制

标签 c++ boost boost-log

我在多个项目中使用了 boost log 并且刚刚发现我应该使用/构建库的方式的限制取决于软件组件类型静态或共享我开发 ode 参见 here

The library has a separately compiled part which should be built as described in the Getting Started guide. One thing should be noted, though. If your application consists of more than one module (e.g. an exe and one or several dll's) that use Boost.Log, the library must be built as a shared object. If you have a single executable or a single module that works with Boost.Log, you may build the library as a static library.

对该限制有解释/原因吗?

最佳答案

这是因为此库包含具有内部 链接和静态存储持续时间的对象。将此类对象放入共享库有助于确保在运行时不存在此类对象的拷贝。

请注意,具有外部 链接的静态存储持续时间对象不受此影响:如果在链接时存在重复定义 - 链接器会在运行时提示 - 只有第一个可用的定义是用过。

关于c++ - 为什么 boost::log 的链接限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21583819/

相关文章:

c++ - 针对 Boost.Log 的 g++ 静态链接错误

c++ - boost 日志链接器错误

c++ - C++ std::string 中是否有任何函数可以计算两个字符串的相同起始字符总数或任何最佳方法

c++ - 如何将对象作为另一个类构造函数的参数传递?

C++:如何使用 boost::property_tree 创建一个数组?

具有任意类型值的 C++ 关联数组

c++ - 返回 vector<Foo> 或 shared_ptr<vector<Foo>>?

C++:静态函数的模板?

c++ - 基于 c++ 范围的 std::vector 迭代的顺序

c++ - 跨二进制模块实现单例