Win7 编译安装log4cxx c++日志类

       log4cxx是Apache的Log4j的一个C++版本,我今天在win7+VS2010环境下进行了编译安装,中间出了一些问题,查资料发现每个人遇到的问题不完全相同,有一些我就没有遇到,这里记录一下我遇到的各个问题以及解决的方法。

首先要下载log4cxx 以及 apr 和 apr-util 源码:

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

apr:http://apache.etoak.com//apr/apr-1.4.6-win32-src.zip

apr-util:http://apache.etoak.com//apr/apr-util-1.4.1-win32-src.zip

 

根据官方的说明,进行处理,只有几个命令,非常不清楚:

Preparation

unzip apr-1.2.11-win32-src.zip
rename apr-1.2.11 apr
unzip apr-util-1.2.10-win32-src.zip
rename apr-util-1.2.10 apr-util
cd apache-log4cxx-0.10.0
configure
configure-aprutil

configure.bat copies the prefabricated log4cxx.hw and private/log4cxx_private.hw over to log4cxx.h and private/log4cxx_private.h.

configure-aprutil.bat uses "sed" to modify apu.hw and apr_ldap.hw to disable APR-Iconv and LDAP which are not necessary for log4cxx and problematic to build. If "sed" is not available, the modifications would be trivial to do in any text editor.

Use the Win32 source zips for APR and APR-Util to preserve the required line endings for the project files. Directories need to be renamed to "apr" and "apr-util" respectively.

Building log4cxx.dll

Open projects/log4cxx.dsw with Microsoft Visual Studio 6 or later at which time you may be prompted to upgrade the projects to the format used by your version of Microsoft Visual Studio.

Select log4cxx as active project and build.

上面只说了解压,重命名,运行批处理,编译log4cxx.dll,也没说目录结构式怎么样的,linux下的sed命令在windows下没有怎么处理。

google一下后发现,解压后的三个文件夹必须放在同一个目录下,其结构为:

D:\log4cxx_apache\

            |_    apr

            |_    apr-util

            |_    apache-log4cxx-0.10.0

然后运行cmd, 切换至 apache-log4cxx-0.10.0 目录,运行configure.bat,这个没有问题。

继续执行apache-log4cxx-0.10.0 目录下的configure-aprutil.bat,这个时候就会出现没有找到sed程序,对于这个问题,有两种方法,我使用的是第二种:

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

              #define APU_HAVE_APR_ICONV 1

              改为

              #define APU_HAVE_APR_ICONV 0       

        2、http://getgnuwin32.sourceforge.net/下载sed并安装,安装后把C:\Program Files\GnuWin32\bin添加入path环境变量。完成之后在运行configure-aprutil.bat(需要把先前的cmd窗口关掉后再打开,这样环境变量才会生效)。

 

然后编译log4cxx工程,build的时候,出现错误:D:\log4cxx_apache\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

 

再编译,出现..\src\main\cpp\stringhelper.cpp(64): error C2039: “insert_iterator”: 不是“std”的成员' 等错误.

解决方法:在该 .cpp 中(stringhelper.cpp) 加入头文件 <iterator>。

 

再编译,出现“无法解析的外部符号”错误

解决方法:将 apr, aprutil, xml 添加至 log4cxx 的引用中。其中apr和xml都在log4cxx所在的solution中,aprutil工程位于apr-util文件夹下,需要先把该工程添加到solution中,然后再工程的属性菜单下的通用属性选项卡下的框架和应用中把那三个工程添加到引用。

 

再编译,我以为马上要OK了,结果没有,出现了 'apu.h': No such file or directory 错误,apu.h.in和apu.hw倒是存在,我以为configure会搞定这些,结果没有,然后我就把apu.hw后面那个w删除了,再编译就OK了,终于出现了log4cxx.lib和log4cxx.dll两个文件。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值