I recently used the log4cxx library in linux and compiled it according to the method provided in its official documentation, I also used google to search several Chinese Blogs and told me how to compile and use the log4cxx library in linux. I still cannot succeed. Here I advise my friends who write blogs or repost blog guides, first, you must at least write your own post based on the Compilation you have written or reproduced. There are several obvious low-level errors. In addition, we recommend that you attach the specific linux system and version you compile to form a complete information chain. You must be responsible for yourself or reposted articles.
The following describes how to compile log4cxx:
CentOS 6.3 Linux kernel version 2.6g ++ (GCC) 4.4.6
The detailed compilation process is as follows:1. Download and decompress
Http://logging.apache.org/log4cxx/
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
Ii. Compilation and Installation
First install apr-1.4.6, Switch cd apr-1.4.6, configure./configure -- prefix =/usr/local/apr, then make, make install
Next install apr-util-1.4.1, Switch to cd .. /apr-util-1.4.1 ,. /configure -- prefix =/usr/local/apr-util -- with-apr =/usr/local/apr, then make, make install;
Last install apache-log4cxx-0.10.0, Switch cd .. /apache-log4cxx-0.10.0, configure. /configure -- prefix =/usr/local/log4cxx -- with-apr =/usr/local/apr -- with-apr-util =/usr/local/apr-util
Note:
1. vim src/main/cpp/inputstreamreader. cpp
Add # 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>
+
Otherwise, inputstreamreader. cpp: 66: error: 'memmove 'was not declared in this scope
Make [3]: *** [inputstreamreader. lo] Error 1
2. vim src/main/cpp/socketoutputstream. cpp
Add # 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>
+
Otherwise socketoutputstream. cpp: 52: error: 'memcpy' was not declared in this scope
3. vim src/examples/cpp/console. cpp
Add # include <string. h>, # include <stdio. h>;
+
# Include <stdio. h>
+
# Include <stdlib. h>
+
# Include <string. h>
+
# Include <log4cxx/logger. h>
# Include <log4cxx/leleappender. h>
# Include <log4cxx/simplelayout. h>
# Include <log4cxx/logmanager. h>
# Include <iostream>
# Include <locale. h>
Otherwise
Console. cpp: In function 'int main (int, char **)':
Console. cpp: 58: Error: 'puts' not declared in this scope
Iii. Test1. Code: # include <log4cxx/logger. h>
# Include <log4cxx/logstring. h>
# Include <log4cxx/propertyconfigurator. h>
Int main (int argc, char * argv [])
{
Using namespace log4cxx;
// Read the configuration file
PropertyConfigurator: configure ("conf. log ");
// Create two logger
LoggerPtr logger1 = Logger: getLogger ("TraceYourMama ");
LoggerPtr logger2 = Logger: getLogger ("Patch ");
LOG4CXX_TRACE (logger1, "trace ");
LOG4CXX_WARN (logger1, "warning ");
LOG4CXX_DEBUG (logger1, "debug ");
LOG4CXX_ASSERT (logger1, false, "asserted ");
LOG4CXX_FATAL (logger1, "Fatal ");
LOG4CXX_TRACE (logger2, "trace ");
LOG4CXX_ERROR (logger2, "error ");
Return 0;
}
Configuration File conf. log Content log4j. rootLogger = TRACE, stdout, logfile
Log4j. appender. stdout = org. apache. log4j. leleappender
Log4j. appender. stdout. layout = org. apache. log4j. PatternLayout
Log4j. appender. stdout. layout. ConversionPattern = % d [% t] %-5 p % 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] %-5 p % c-% m %
Remember to run export LD_LIBRARY_PATH =/usr/local/log4cxx/lib: $ LD_LIBRARY_PATH
This article from "forever friends" blog, please be sure to keep this source http://yaocoder.blog.51cto.com/2668309/980276