我在多个项目中使用了 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/