How to Compile and link log4cpp programs?
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
Comments: