log4cxx在linux下的编译使用推荐

最近在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.gz1.tar zxvf apr-1.4.6.tar.gz2.tar zxvf apr-util-1.4.1.tar.gz3.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 scopemake[3]: *** [inputstreamreader.lo] 错误 12.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 scope3.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, logfilelog4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c – %m%nlog4j.appender.logfile=org.apache.log4j.RollingFileAppenderlog4j.appender.logfile.File=./ZW.loglog4j.appender.logfile.MaxFileSize=100KBlog4j.appender.logfile.MaxBackupIndex=10log4j.appender.logfile.layout=org.apache.log4j.PatternLayoutlog4j.appender.logfile.layout.ConversionPattern=%d [%t] %-5p %c – %m%运行时记得export LD_LIBRARY_PATH=/usr/local/log4cxx/lib:$LD_LIBRARY_PATH 值不值得,真是不足为外人道,自己心里有数就行。

log4cxx在linux下的编译使用推荐

相关文章:

你感兴趣的文章:

标签云: