文档库 最新最全的文档下载
当前位置:文档库 › boost.log在boost1.47下的编译总结

boost.log在boost1.47下的编译总结

boost.log在boost1.47下的编译总结

看网上说boost.log已经被boost组织接受了,可从官网下载的最新的boost1.47版本里面并没有boost.log。
到boost.log的网站上一看,原来组织还有一些要求没有达到,比如编译慢,某些地方的performance还待提高等等。
不过就算如此,boost.log也是当下最好的免费开源C++log库了。
下载最新的boost-log-1.0,解压后,把里面的东东copy到boost1.47对应的文件夹下。
开始编译,boost的编译方法网上有很多,大家可以参考:

https://www.wendangku.net/doc/045068411.html,/wondering/archive/2009/05/21/boost_setup.html
我的编译命令如下:

bjam install --tooset=msvc-9.0 --without-graph --without-graph_parallel --without-math --without-mpi --without-python --without-serialization --without-wave --prefix="F:\download\boost_1_47_0\bin\vc9" link=shared runtime-link=shared threading=multi debug
编译了我平时可能用的和boost.log依赖的几个库。

好事多磨,果然boost.log报了一堆奇怪的错误。

最后还是在官网论坛上找到原因,原来boost.log1年多没更新了还是只能和filesystem v2一起编译,而boost1.47默认已经是filesystem v3了,而且已经声明即将在1.48完全抛弃v2了。

找到原因就好办了,打开boost_1_47_0\boost\config\user.hpp,在最后添加一个宏定义如下:


#define BOOST_FILESYSTEM_VERSION 2
如此之后,再编译boost.log没有错了,但其他库又报错了,晕~~。
好吧,先把上面的宏定义注释掉,将除boost.log的其他库用filesystem v3编译好,命令如下:


bjam install --tooset=msvc-9.0 --without-graph --without-graph_parallel --without-math --without-mpi --without-python --without-serialization --without-wave --without-log --prefix="F:\download\boost_1_47_0\bin\vc9" link=shared runtime-link=shared threading=multi debug
这样除了boost.log都编译好了。
然后恢复上面的宏定义,用如下命令编译boost.log


bjam install --tooset=msvc-9.0 --disable-filesystem3 --with-log --prefix="F:\download\boost_1_47_0\bin\vc9" link=shared runtime-link=shared threading=multi debug
终于所有的库都编译好了。
启动VS2008,工具->选项,左边选择:项目和解决方案->VC++目录,右边选:包含文件,加入"F:\download\boost_1_47_0\bin\vc9\include\boost-1_47",再选择:库文件,加入"F:\download\boost_1_47_0\bin\vc9\lib"。

下一步,在系统的PATH环境变量的最后加入"F:\download\boost_1_47_0\bin\vc9\lib"。

最后重启VS2008,写个小程序,编译通过,链接报LINK : fatal error LNK1104: 无法打开文件“libboost_log-vc90-mt-gd-1_47.lib”。

原来,boost默认是以静态方式连接的,而我们用的是dll动态链接库。

所以,还需要在stdafx.h的开始加入以下宏定义:

#define BOOST_ALL_DYN_LINK
之后,编译连接OK,大功告成。
测试例子如下:
[cpp]

view plaincopy
#include "stdafx.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

namespace logging = boost::log;
namespace fmt = boost::log::formatters;
namespace flt = boost::log::filters;
namespace sinks = boost::log::sinks;

using boost::shared_ptr;

void init()
{
logging::init_log_to_file
(
logging::keywords::file_name = "sample_%N.log", // file name pattern
logging::keywords::rotation_size = 10 * 1024 * 1024, // rotate files every 10 MiB...
// ...or at midnight
logging::keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0),
logging::keywords::format = "[%TimeStamp%]: %_%" // log record format
);

logging::core::get()->set_filter
(
flt::attr< logging::trivial::severity_level >("Severity") >= logging::trivial::info
);
}

int _tmain(int argc, _TCHAR* argv[])
{
init();
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;
}

相关文档
相关文档 最新文档