[转]vs2010 编译 log4cxx 0.10.0

原文:http://www.cnblogs.com/walfud/articles/2453738.html

1. 下载 log4cxx 以及 apr 和 apr-util 源码:

a) http://www.apache.org/dyn/closer.cgi/logging/log4cxx/0.10.0/apache-log4cxx-0.10.0.zip

b) http://archive.apache.org/dist/apr/apr-1.2.11-win32-src.zip

c) http://archive.apache.org/dist/apr/apr-util-1.2.10-win32-src.zip

image

 

2. 将 3 个压缩包解压到同一个目录.

image

 

3. 将 apr-1.2.11 重命名为 apr, 将 apr-util-1.2.10 重命名为 apr-util.

image

最终如下:

image

 

4. 使用 cmd, 切换至 apache-log4cxx-0.10.0 目录, 运行 configure.bat

image

 

5. 在与第 4  步同一目录下的 cmd 中, 执行 configure-aprutil.bat

1) 此时, 如果环境变量中没有 sed 程序, 则会出现:

image

此时应该:

手动修改 apr-util\include\apu.hw 里的内容

#define APU_HAVE_APR_ICONV 1

改为

#define APU_HAVE_APR_ICONV 0

2) 如果系统可以找到 sed 程序, 那么会出现:

image

 

6. 打开 apache-log4cxx-0.10.0\projects 下的 log4cxx.dsw

image

打开工程会提示转换:

image

 

7. 将 log4cxx 设置为启动项.

image

 

8. 开始编译. 快捷键 F7.

image

 

9.

1) 出现

'4>D:\log4cxx-src\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

image

 

2) 出现

'2>network_io\unix\multicast.c(137): error C2079: “mip”使用未定义的 struct“group_source_req"' 等错误.

image

双击第一行出错输出, 将 136 和 148 行的 #if MCAST_JOIN_SOURCE_GROUP 注释, 替换为 #if defined (group_source_req)

 

image

 

3) 出现

'4>..\src\main\cpp\stringhelper.cpp(64): error C2039: “insert_iterator”: 不是“std”的成员' 等错误.

image

在该 .cpp 中(stringhelper.cpp) 加入头文件 <iterator>:

image

 

4) 出现

'无法解析的外部符号 xxx' 等错误.

image

将 apr, aprutil, xml 添加至 log4cxx 的引用中.

image

 

10. 选择重新生成解决方案. 否则可能会造成 '无法打开 apr_iconv.h' 错误. 个人怀疑是第 5 步中, configure-aprutil.bat 脚本中的 sed 命令没有正确更新文件的时间所致.

image

编译成功后:

image

 

reference:

http://cn.waterlin.org/cpp/log4cxx.html

http://blog.csdn.net/rabbit729/article/details/2772179

http://blog.csdn.net/kungbx/article/details/6129564

http://hi.baidu.com/gaocher/blog/item/8f17e92729a56c7635a80ff2.html

http://blog.csdn.net/everettjf/article/details/6194933

http://hi.baidu.com/antbean1988/blog/item/40b2531cf8d271d3c3fd7898.html

http://hi.baidu.com/antbean1988/blog/item/40b2531cf8d271d3c3fd7898.html