【问题标题】:Boost log marcro explainationBoost日志宏解释
【发布时间】: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 来编译?

【问题讨论】:

    标签: c++ boost boost-log


    【解决方案1】:

    #define BOOST_LOG_DYN_LINK

    将强制所有具有自己独立源的库链接为 dll 而不是静态库。

    参考:\boost_1_xx_0\boost\config\user.hpp 了解详情

    要配置boost,请使用用户配置标头&lt;boost/config/user.hpp&gt;

    【讨论】:

    • 这意味着日志库不能作为静态库加载。我必须将它加载为动态库?
    • 恕我直言,在尝试编译示例时,静态 boost 库可能不可用。 (抱歉,无法回答这个问题)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-09
    • 2013-01-19
    • 1970-01-01
    • 2017-06-15
    • 1970-01-01
    相关资源
    最近更新 更多