【发布时间】:2013-10-08 15:18:53
【问题描述】:
我在这里遵循了 boost log 教程 http://boost-log.sourceforge.net/libs/log/doc/html/index.html
我尝试编译并运行这个示例
//[ example_tutorial_trivial
#include <boost/log/trivial.hpp>
int main(int, char*[])
{
BOOST_LOG_TRIVIAL(trace) << "A trace severity message";
BOOST_LOG_TRIVIAL(debug) << "A debug severity message";
BOOST_LOG_TRIVIAL(info) << "An informational severity message";
BOOST_LOG_TRIVIAL(warning) << "A warning severity message";
BOOST_LOG_TRIVIAL(error) << "An error severity message";
BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message";
return 0;
}
无法编译。错误返回为http://pastebin.com/DcLdWGke
然后我编辑我的代码如下:
#define BOOST_LOG_DYN_LINK
//[ example_tutorial_trivial
#include <boost/log/trivial.hpp>
int main(int, char*[])
{
BOOST_LOG_TRIVIAL(trace) << "A trace severity message";
BOOST_LOG_TRIVIAL(debug) << "A debug severity message";
BOOST_LOG_TRIVIAL(info) << "An informational severity message";
BOOST_LOG_TRIVIAL(warning) << "A warning severity message";
BOOST_LOG_TRIVIAL(error) << "An error severity message";
BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message";
return 0;
}
现在它符合要求并且运行良好。我在 boost 网站上读到了这个宏:
如果在用户代码中定义,库将假定二进制文件已构建 作为动态加载的库(“dll”或“so”)。否则就是 假设库是在静态模式下构建的。这个宏必须是 为用户的所有翻译单元定义或未定义 使用日志记录的应用程序。这个宏可以帮助自动链接 在支持它的平台上。
所以我的问题是:为什么我需要#define BOOST_LOG_DYN_LINK 来编译?
【问题讨论】: