linux 编译安装log4cxx

Apache log4cxx是一个继Apache log4j之后用于C++的日志框架。Apache log4cxx使用Apache Portable Runtime作为大部分的平台相关代码,可以用于任何支持APR的平台。

官网: http://logging.apache.org/log4cxx/


首先从 https://github.com/apache/log4cxx/tree/mcatan 下载源代码,目前最新的版本是0.10.0

git clone https://github.com/apache/log4cxx.git

这时直接./configure 会报错,找不到apr和apr-uitl, 所以还需要先安装这2个包

wget http://mirrors.hust.edu.cn/apache//apr/apr-1.5.2.tar.gz

wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.4.tar.gz


先编译安装apr

tar xzvf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure
make
make install


然后编译安装apr-util
tar xzvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure
make
make install


最后编译安装log4cxx

cd log4cxx
./configure
make
make instal

如果不能打印中文日志可以重新 configure编译,如下

./configure --with-charset=utf-8 --with-logchar=utf-8
make
make install

在编译的时候我报了一个错,如下

In file included from ../../../src/main/include/log4cxx/spi/filter.h:24:0,
                 from ../../../src/main/include/log4cxx/filter/andfilter.h:27,
                 from andfilter.cpp:18:
../../../src/main/include/log4cxx/spi/loggingevent.h:171:45: error: declaration of 'typedef log4cxx::spi::KeySet log4cxx::spi::LoggingEvent::KeySet' [-fpermissive]
                         typedef spi::KeySet KeySet;
                                             ^
In file included from ../../../src/main/include/log4cxx/helpers/objectptr.h:21:0,
                 from ../../../src/main/include/log4cxx/spi/filter.h:21,
                 from ../../../src/main/include/log4cxx/filter/andfilter.h:27,
                 from andfilter.cpp:18:
../../../src/main/include/log4cxx/spi/loggingevent.h:46:34: error: changes meaning of 'KeySet' from 'typedef class std::vector<std::basic_string<char> > log4cxx::spi::KeySet' [-fpermissive]
                 LOG4CXX_LIST_DEF(KeySet, LogString);


打开报错的文件 loggingevent.h ,将 typedef spi::KeySet KeySet 移动到 KeySet getMDCKeySet() const; 这个函数声明之前

typedef spi::KeySet KeySet;
KeySet getMDCKeySet() const;





你可能感兴趣的:(log4cxx安装,log4cxx,log4cxx编译)