Linux under compilation installation Log4cxx
A Project Server side under the Linux platform, the open source log library Log4cxx, this library is a sub-library of Apache project. The function is very good. The following is a record of its compilation and installation process.
Log4cxx's official is http://logging.apache.org/log4cxx/index.html, I use 0.10.0 version.
In order to compile it, also need two auxiliary library, Apr, and apr-util, can download http://apr.apache.org/download.cgi here, I use the version is apr-1.3.8.tar.gz and apr-util-1.3.9.tar.gz.
The first step installs apr-1.3.8, the order cannot be wrong, it must install first
$tar ZXVF apr-1.3.8.tar.gz
$CD apr-1.3.8
$./configure--prefix=/usr/local
$make
$SU Root
$make Install
Then install apr-util-1.3.9
$tar ZXVF apr-util-1.3.9.tar.gz
$CD apr-util-1.3.9
$./configure--prefix=/usr/local--WITH-APR=/USR/LOCAL/APR
$make
$SU Root
$make Install
Configure option--WITH-APR=/USR/LOCAL/APR Specify the location of the APR library
Finally, we can install Log4cxx.
$tar ZXVF apache-log4cxx-0.10.0.tar.gz
$CD apache-log4cxx-0.10.0
$configure--prefix==/usr/local
$make
$SU Root
$make Install
Because compiled into a shared library, and finally set the next search directory, edit ~/.BASHRC, add the following two lines
Ld_library_path=/usr/local/lib
Export Ld_library_path
OK, so log4cxx is ready to install.
Finally write a program, test under.
#include <log4cxx/logger.h>
#include <log4cxx/logstring.h>
#include <log4cxx/propertyconfigurator.h>
int main (int argc, char* argv[])
{
using namespace Log4cxx;
Reading configuration Files
Propertyconfigurator::configure ("Log4cxx.cfg");
Establishment of two logger
Loggerptr logger1 = Logger::getlogger ("Traceyourmama");
Loggerptr logger2 = Logger::getlogger ("Patch");
Log4cxx_trace (Logger1, "tracking");
Log4cxx_warn (Logger1, "warning");
Log4cxx_debug (Logger1, "commissioning");
Log4cxx_assert (Logger1, False, "assertion");
Log4cxx_fatal (Logger1, "deadly");
Log4cxx_trace (Logger2, "tracking");
Log4cxx_error (Logger2, "error");
return 0;
}
Compiling links
$g + +-o main main.cpp-llog4cxx
OK, finish the manual.
Finally install Log4cxx when there will be errors, missing header files, according to the wrong file to add