How to Compile and link log4cpp programs?

Posted by Joys of Programming on in C/C++

log4cpp, used for logging in C++ can be installed from packages or from the source code. But while programming with log4cpp, you must be aware of certain aspects like the location of the log4cpp headers and log4cpp library.

The simplest way to find out the location of the headers


$ log4cpp-config --cflags
-I/usr/local/include -O2 -DNDEBUG

The next important thing is to find out the library to be linked


$ log4cpp-config --libs

-L/usr/local/lib -llog4cpp

Once you have found this, now you can easily compile a log4cpp program. Take for example, this sample log4cpp program. To compile this program, you can either substitute the above values


g++ log.cpp -L/usr/local/lib -llog4cpp -I/usr/local/include -O2 -DNDEBUG

or simply use the command log4cpp-config command


g++ NewPatternLayout.cpp `log4cpp-config --libs --cflags`

In most cases, you need to simply write the command


g++ log.cpp -llog4cpp


Tags: , , , ,

Comments:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2009-2012 Joys of Programming All rights reserved.
Desk Mess Mirrored v1.8.1 theme from BuyNowShop.com.