linux 下编译log4cxx

本文介绍如何在支持APR的平台上安装Apachelog4cxx日志框架,包括安装apr和apr-util依赖,解决常见错误及配置中文日志。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值