一. 简介
log4cxx是Java社区著名的log4j的c++移植版,用于为C++程序提供日志功能,以便开发者对目标程序进行调试和审计,log4cxx是apache软件基金会的开源项目,基于APR实现跨平台支持。一个良好的日志系统不管是开发、调试和维护,对一个项目来说是多么的重要,我想做过开发的同学深知这点。我用过的日志框架比较少,所以在这里不做与其它日志框架的比较,类似的日志框架还有GLog、boost log,如果有兴趣可以去研究一下。
二. 下载安装
1. 下载:
1). 环境:Windows 8
2). 依赖:apr、apr-util
3). apr 下载地址: http://download.youkuaiyun.com/detail/u013354805/9035589
4). apr-util 下载地址:http://download.youkuaiyun.com/detail/u013354805/9035995
5). log4cxx下载地址:http://download.youkuaiyun.com/detail/u013354805/9035581
6). 下面是官方网站:
a). apr、apr-util下载地址:http://apr.apache.org/download.cgi
b). log4cxx下载地址:http://logging.apache.org/log4cxx/download.html
2. 将 3 个压缩包解压到同一个目录.如下图:
3. 将 apr-1.2.11 重命名为 apr, 将 apr-util-1.2.10 重命名为 apr-util.如下图:
4. 打开命令行:
Win 8:Win+X"快捷键=>直接调出多个快捷命令=>命令提示符(管理员) |
5. 在第四步骤输入:
1. cd D:\log4cxx\apache-log4cxx-0.10.0 回车 2. d: 回车后 切换至 apache-log4cxx-0.10.0 目目录 |
6. 再第五步的基础上输入:
configure.bat 回车 |
7. 在第六步的基础上输入:
configure-aprutil.bat 回车 |
8. 进入下面目录:
1. D:\log4cxx\apr-util\include 2. 找apu.hw文件 |
9. 用Notepad++ 打开apu.hw文件(记事本也可以)
手动修改 apr-util\include\apu.hw 里的内容 #define APU_HAVE_APR_ICONV1 改为 #define APU_HAVE_APR_ICONV0 |
10. 使用VS2010打开 apache-log4cxx-0.10.0\projects 下的 log4cxx.dsw
打开工程会提示转换:
11. 转换好后工程如下图:
12. 将 log4cxx 设置为启动项.
设置后:
13. 开始编译.log4cxx:
出现
4>D:\log4cxx\apache-log4cxx-0.10.0\src\main\include\log4cxx/spi/loggingevent.h(155): error C2252: 只能在命名空间范围内显式实例化模板 |
a) 双击 "输出" 窗口中的错误行, 此时会在 "代码窗口" 中出现错误的位置.如下图
b) 选择 LOG4CXX_LIST_DEF, 按键盘 F12, 此时会跳转到该宏的定义,如下图
c) 将
#define LOG4CXX_LIST_DEF(N, T) \ template class LOG4CXX_EXPORT std::allocator<T>; \ template class LOG4CXX_EXPORT std::vector<T>; \ typedef std::vector<T> N |
替换为:
#define LOG4CXX_LIST_DEF(N, T) \ typedef std::vector<T> N |
出现
2>network_io\unix\multicast.c(137): error C2079: “mip”使用未定义的struct “group_source_req”错误 |
双击第一行出错输出, 将 136 和 148 行的 #if MCAST_JOIN_SOURCE_GROUP 注释, 替换为 #if defined (group_source_req) |
出现
'4>..\src\main\cpp\stringhelper.cpp(64): error C2039: “insert_iterator”: 不是“std”的成员' 等错误. |
在该 .cpp 中(stringhelper.cpp) 加入头文件 #include<iterator> |
16. 按照15修改后,重新编译, 出现
'无法解析的外部符号 xxx' 等错误. |
将 apr, aprutil, xml 添加至 log4cxx 的引用中.(按照下面4副图的顺序操作) |