程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> log4cxx在linux下的編譯使用

log4cxx在linux下的編譯使用

編輯:關於C語言

     最近在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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved