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

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

这时直接./configure 会报错,找不到apr和apr-uitl, 所以还需要先安装这2个包
  1. wget http://mirrors.hust.edu.cn/apache//apr/apr-1.5.2.tar.gz  
  2.   
  3. wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.4.tar.gz  


先编译安装apr

  1. tar xzvf apr-1.5.2.tar.gz  
  2. cd apr-1.5.2  
  3. ./configure  
  4. make  
  5. make install  


然后编译安装apr-util
  1. tar xzvf apr-util-1.5.4.tar.gz  
  2. cd apr-util-1.5.4  
  3. ./configure  
  4. make  
  5. make install  


最后编译安装log4cxx
  1. run
    ./autogen.sh
    ./configure
    make
    make install


如果不能打印中文日志可以重新 configure编译,如下
  1. ./configure --with-charset=utf-8 --with-logchar=utf-8  
  2. make  
  3. make install  

在编译的时候我报了一个错,如下
  1. In file included from ../../../src/main/include/log4cxx/spi/filter.h:24:0,  
  2.                  from ../../../src/main/include/log4cxx/filter/andfilter.h:27,  
  3.                  from andfilter.cpp:18:  
  4. ../../../src/main/include/log4cxx/spi/loggingevent.h:171:45: error: declaration of 'typedef log4cxx::spi::KeySet log4cxx::spi::LoggingEvent::KeySet' [-fpermissive]  
  5.                          typedef spi::KeySet KeySet;  
  6.                                              ^  
  7. In file included from ../../../src/main/include/log4cxx/helpers/objectptr.h:21:0,  
  8.                  from ../../../src/main/include/log4cxx/spi/filter.h:21,  
  9.                  from ../../../src/main/include/log4cxx/filter/andfilter.h:27,  
  10.                  from andfilter.cpp:18:  
  11. ../../../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]  
  12.                  LOG4CXX_LIST_DEF(KeySet, LogString);  


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

    在使用过程中 需要配置环境变量 export LD_LIBRARY_PATH=/usr/local/lib   编译选项-l log4cxx 。如果是Qt下,在项目选项中有构建环境增加前面变量,在pro文件中增加lib

猜你喜欢

转载自blog.csdn.net/qq_28016947/article/details/51014205