最近在linux下使用log4cxx库,按照其官方文档提供的方法来进行编译,不能成功,又利用google搜索了好几个中文博客上讲述在linux下编译使用log4cxx库的方法,依然不能成功,在这里我奉劝写博客或是转载博客指导人的朋友们,首先您起码得自己按照您写的或是转载的编译通过了再发表文章吧,其中有几处明显的低级错误,另外,建议您把你编译时的具体的linux系统及版本附带上,这样才能够成一条完整的信息链,一定要对自己或是转载的文章负责。

 
下面我把我编译log4cxx过程给大家讲述下:
 
系统平台
CentOS 6.3   linux内核版本 2.6   g++ (GCC) 4.4.6 
 
以下是详细的编译过程:
一.下载解压
http://logging.apache.org/log4cxx/, http://apr.apache.org/

apr-1.4.6.tar.gz,  apr-util-1.4.1.tar.gz,  apache-log4cxx-0.10.0.tar.gz

1.tar zxvf apr-1.4.6.tar.gz
2.tar zxvf apr-util-1.4.1.tar.gz
3.tar zxvf apache-log4cxx-0.10.0.tar.gz

二 .编译安装
首先安装apr-1.4.6,切换cd apr-1.4.6,配置./configure --prefix=/usr/local/apr,接着make, make install

接着安装apr-util-1.4.1,切换至cd ../apr-util-1.4.1, ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr,接着make,make install;

最后安装apache-log4cxx-0.10.0,切换cd ../apache-log4cxx-0.10.0,配置./configure --prefix=/usr/local/log4cxx --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
注意配置前需进行以下操作:
1.vim src/main/cpp/inputstreamreader.cpp
增加#include <string.h>;
#include <log4cxx/logstring.h>
#include <log4cxx/helpers/inputstreamreader.h>
#include <log4cxx/helpers/exception.h>
#include <log4cxx/helpers/pool.h>
#include <log4cxx/helpers/bytebuffer.h>
+
#include <string.h>
+
否则会出现inputstreamreader.cpp:66: error: 'memmove' was not declared in this scope
make[3]: *** [inputstreamreader.lo] 错误 1

2.vim src/main/cpp/socketoutputstream.cpp
增加#include <string.h>;
#include <log4cxx/logstring.h>
#include <log4cxx/helpers/socketoutputstream.h>
#include <log4cxx/helpers/socket.h>
#include <log4cxx/helpers/bytebuffer.h>
+
#include <string.h>
+
否则会出现socketoutputstream.cpp:52: error: 'memcpy' was not declared in this scope

3.vim src/examples/cpp/console.cpp
增加#include <string.h>,#include <stdio.h>;
+
#include <stdio.h>
+
#include <stdlib.h>
+
#include <string.h>
+
#include <log4cxx/logger.h>
#include <log4cxx/consoleappender.h>
#include <log4cxx/simplelayout.h>
#include <log4cxx/logmanager.h>
#include <iostream>
#include <locale.h>
否则会出现
console.cpp: In function ‘int main(int, char**)’:
console.cpp:58: 错误:‘puts’在此作用域中尚未声明

 
三.测试
1.代码:
#include <log4cxx/logger.h>    
#include <log4cxx/logstring.h> 
#include <log4cxx/propertyconfigurator.h>

int main(int argc, char* argv[]) 

        using namespace log4cxx;

// 读取配置文件 
        PropertyConfigurator::configure("conf.log");

// 建立两个logger 
        LoggerPtr logger1 = Logger::getLogger("TraceYourMama"); 
        LoggerPtr logger2 = Logger::getLogger("Patch");

LOG4CXX_TRACE(logger1, "跟踪"); 
        LOG4CXX_WARN(logger1, "警告"); 
        LOG4CXX_DEBUG(logger1, "调试"); 
        LOG4CXX_ASSERT(logger1, false, "断言"); 
        LOG4CXX_FATAL(logger1, "致命");

LOG4CXX_TRACE(logger2, "跟踪"); 
        LOG4CXX_ERROR(logger2, "错误"); 
        return 0; 
}

配置文件conf.log的内容
log4j.rootLogger=TRACE, stdout, logfile

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=./ZW.log
log4j.appender.logfile.MaxFileSize=100KB
log4j.appender.logfile.MaxBackupIndex=10
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d [%t] %-5p %c - %m%

运行时记得
export LD_LIBRARY_PATH=/usr/local/log4cxx/lib:$LD_LIBRARY_PATH
 

本文出自 “永远的朋友” 博客,请务必保留此出处http://yaocoder.blog.51cto.com/2668309/980276

log4cxx在linux下的编译使用的更多相关文章

  1. log4cxx在linux下的编译和使用

    [下载] [编译动态库] [使用动态库]

  2. LINUX下文件编译

    body, table{font-family: 微软雅黑} table{border-collapse: collapse; border: solid gray; border-width: 2p ...

  3. ACE-6.1.0 linux 下的编译与安装步骤

    ACE-6.1.0 linux 下的编译与安装步骤  引用至http://www.cnblogs.com/liangxiaxu/archive/2013/03/07/2948417.html 1.从  ...

  4. FFmpeg在Linux下安装编译过程

    转载请把头部出处链接和尾部二维码一起转载,本文出自:http://blog.csdn.net/hejjunlin/article/details/52402759 今天介绍下FFmpeg在Linux下 ...

  5. Linux下nginx编译安装教程和编译参数详解

    这篇文章主要介绍了Linux下nginx编译安装教程和编译参数详解,需要的朋友可以参考下 一.必要软件准备1.安装pcre 为了支持rewrite功能,我们需要安装pcre 复制代码代码如下: # y ...

  6. linux下将编译错误输出到一个文本文件

    linux下将编译错误输出到一个文本文件 command > filename 把把标准输出重定向到一个新文件中 command > > filename 把把标准输出重定向到一个文 ...

  7. 从四个问题透析Linux下C++编译&链接

    摘要:编译&链接对C&C++程序员既熟悉又陌生,熟悉在于每份代码都要经历编译&链接过程,陌生在于大部分人并不会刻意关注编译&链接的原理.本文通过开发过程中碰到的四个典型 ...

  8. [转]Linux下g++编译与使用静态库(.a)和动态库(.os) (+修正与解释)

    在windows环境下,我们通常在IDE如VS的工程中开发C++项目,对于生成和使用静态库(*.lib)与动态库(*.dll)可能都已经比较熟悉,但是,在linux环境下,则是另一套模式,对应的静态库 ...

  9. linux 下cmake 编译 ,调用,调试 poco 1.6.0 小记

    上篇文章 小记了: 关于 Poco::TCPServer框架 (windows 下使用的是 select模型) 学习笔记. http://www.cnblogs.com/bleachli/p/4352 ...

随机推荐

  1. Codeforces Round #345 (Div. 2) A. Joysticks dp

    A. Joysticks 题目连接: http://www.codeforces.com/contest/651/problem/A Description Friends are going to ...

  2. C++ cout输出保留小数

    参考: http://www.cnblogs.com/wushuaiyi/p/4439361.html http://blog.csdn.net/edricbjtu/article/details/4 ...

  3. GMT-CMSP系统维护步骤整理

    一.关闭前端各服务1.北京代理,韩国代理节点nginx/etc/init.d/nginx stop2.关闭WEB1,WEB2 NGINX和PHPpkill nginx && pkill ...

  4. JavaScript基础入门教程(五)

    说明 本系列博客的第一篇已经说明了,要求阅读者需要具有其它语言的编程基础,所以关于组数的基础部分本篇博客将不再赘述,主要讲js中数组的特性. 创建数组 数组的创建主要有两种方法,一种是数组直接量,还有 ...

  5. a<<=n

    a<<=n等价于a=a<<na<<n表示a左移n位(二进制)等价于a乘以2的n次方 a<<=n的含义就是,a等于a乘以2的n次方

  6. LeetCode Add Binary |My Solution

    Given two binary strings, return their sum (also a binary string). For example, a = "11" b ...

  7. actor中!(tell)与forward的差别

    ! 的源代码: def !(message: Any)(implicit sender: ActorRef = Actor.noSender): Unit tell 的源代码: final def t ...

  8. linux最常用命令整理

    linux vim命令跳转到文档开头或末尾 gg:命令将光标移动到文档开头 G:命令将光标移动到文档末尾 <hr/> 网络 # ifconfig # 查看所有网络接口的属性 # iptab ...

  9. Discuz常见小问题2-如何修改整个网站的默认字体为微软雅黑

    界面-风格管理,然后点击默认模板的编辑,在正常字体和小号字体前面加上你要的字体(比如微软雅黑,XXX,XXX),挨个排到后面,如果前面的字体没有则显示后面的 修改之后的效果(注意你不要在页面定义别的C ...

  10. App服务端架构变迁

    随着移动互联网时代的到来,移动技术也随之飞速发展.如今,App已然成为绝大多数互联网企业用来获取用户的核心渠道.以往以PC为主要承载平台的各业务线,源源不断集成加入到移动项目中来,原本以产品为中心快速 ...