`
yand789
  • 浏览: 22325 次
社区版块
存档分类
最新评论

Linux系统编译及测试log4cxx---出现inputstreamreader.cpp:66: error: 'memmove' was not decla

 
阅读更多
http://www.it165.net/os/html/201209/3238.html

log4cxx在linux下的编译使用

Linux系统编译及测试l     最近在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

www.it165.net
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.代码:
og4cxx


view sourceprint?
01.
#include <log4cxx/logger.h>  
02.
#include <log4cxx/logstring.h>
03.
#include <log4cxx/propertyconfigurator.h>
04.

05.
int main(int argc, char* argv[])
06.
{
07.
using namespace log4cxx;
08.

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

12.
// 建立两个logger
13.
LoggerPtr logger1 = Logger::getLogger("TraceYourMama");
14.
LoggerPtr logger2 = Logger::getLogger("Patch");
15.

16.
LOG4CXX_TRACE(logger1, "跟踪");
17.
LOG4CXX_WARN(logger1, "警告");
18.
LOG4CXX_DEBUG(logger1, "调试");
19.
LOG4CXX_ASSERT(logger1, false, "断言");
20.
LOG4CXX_FATAL(logger1, "致命");
21.

22.
LOG4CXX_TRACE(logger2, "跟踪");
23.
LOG4CXX_ERROR(logger2, "错误");
24.
return 0;
25.
}

配置文件conf.log的内容
view sourceprint?
01.
log4j.rootLogger=TRACE, stdout, logfile
02.

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

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

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


本文出自 “永远的朋友” 博客
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics