This Post will show How , to Build Log4cpp Source code and the Compile and run the Sample code as shown in this Simple Example Using Ubuntu . So Lets begin with Downloading the Log4cpp.
The Error will come like below
If the above error comes then what you need to do is to set you environment variable like shown in the following step .
To set the above environment variable follow the following steps
Then when the gedit editor for bashrc file will co to the bottom and paste export LD_LIBRARY_PATH=/usr/local/lib
Now your environment variable is set permanently.
and This time the program will run and show the following output.
---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------
Newest 'log4cpp' Questions
c++ - getting started with log4cpp in ubuntu
C++ programming: A useful log4cpp example
log4cpp
Searches related to Log4Cpp
log4cpp tutorial
log4cxx
log4cpp category
log4cpp vs log4cxx
log4cpp appender
log4cpp documentation
log4cpp configuration file
log4cpp properties file example
The download Source code is available on Sourceforge on this Download Link . So Download the Source and Extract it in your Home directory or wherever you want to extract according to your choice . I have extracted the Log4cpp in my Home directory .
Now Follow the steps below.
- $ cd log4cpp
- $ ./configure
- $ make
- $ sudo make check
- $ sudo make install
Once the above steps are successfully executed then we are ready to Compile and run Sample Example .
Make a C++ file called log4cpp.cpp . and copy and paste the Sample example as shown below .
// log4cpp.cpp
#include "log4cpp/Category.hh"
#include "log4cpp/Appender.hh"
#include "log4cpp/FileAppender.hh"
#include "log4cpp/OstreamAppender.hh"
#include "log4cpp/Layout.hh"
#include "log4cpp/BasicLayout.hh"
#include "log4cpp/Priority.hh"
int main(int argc, char** argv) {
log4cpp::Appender *appender1 = new log4cpp::OstreamAppender("console", &std::cout);
appender1->setLayout(new log4cpp::BasicLayout());
log4cpp::Appender *appender2 = new log4cpp::FileAppender("default", "program.log");
appender2->setLayout(new log4cpp::BasicLayout());
log4cpp::Category& root = log4cpp::Category::getRoot();
root.setPriority(log4cpp::Priority::WARN);
root.addAppender(appender1);
log4cpp::Category& sub1 = log4cpp::Category::getInstance(std::string("sub1"));
sub1.addAppender(appender2);
// use of functions for logging messages
root.error("root error");
root.info("root info");
sub1.error("sub1 error");
sub1.warn("sub1 warn");
// printf-style for logging variables
root.warn("%d + %d == %s ?", 1, 1, "two");
// use of streams for logging messages
root << log4cpp::Priority::ERROR << "Streamed root error";
root << log4cpp::Priority::INFO << "Streamed root info";
sub1 << log4cpp::Priority::ERROR << "Streamed sub1 error";
sub1 << log4cpp::Priority::WARN << "Streamed sub1 warn";
// or this way:
root.errorStream() << "Another streamed error";
return 0;
}
Now its time to compile the above code . SO compile the code with following command -
$ g++ -gstabs+ -w -Iheaders log4cpp.cpp -o log4cpp_exe -llog4cpp -lpthread
And the program will compile successfully but at the time or execution I found of example
- $ ./log4cpp_exe
The Error will come like below
- ERROR : ./log4cpp_inited: error while loading shared libraries: liblog4cpp.so.5: cannot open shared object file: No such file or directory
If the above error comes then what you need to do is to set you environment variable like shown in the following step .
- export LD_LIBRARY_PATH=/usr/local/lib
To set the above environment variable follow the following steps
- $ gedit ~/.bashrc
Then when the gedit editor for bashrc file will co to the bottom and paste export LD_LIBRARY_PATH=/usr/local/lib
Then save the bash file and on terminal execute the following command
- $ source ~/.bashrc
Now your environment variable is set permanently.
Now once again Run the log4cpp_exe
- $ ./log4cpp_exe
and This time the program will run and show the following output.
1352973121 ERROR : root error
1352973121 ERROR sub1 : sub1 error
1352973121 WARN sub1 : sub1 warn
1352973121 WARN : 1 + 1 == two ?
1352973121 ERROR : Streamed root error
1352973121 ERROR sub1 : Streamed sub1 error
1352973121 WARN sub1 : Streamed sub1 warn
1352973121 ERROR : Another streamed error
If you see the above output on console that means your program run successfully
That's it
Build and Run Sample Code for Log4Cpp C++ library from Source Code on Ubuntu
---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------
- Write a C++ program to Make Simple calculator
- Write a C++ program to arrange 10 numbers in ascending order
- Write a C++ program to calculates the following equation for entered numbers (n, x). 1+ (nx/1!) - (n(n-1)x^2/2!)
- Write a C++ program to 1. Initialize Matrices 2. Print Matrices 3. Multiply Matrices 4. Transpose of 2nd Matrix 5. Move Row and Column of 2nd Matrix 6. Quit
- Write the C++ program for processing of the students structure
- Write a C++ program that gets two strings from input and stores them in variables such as str1 and str2
- Write a C++ program that gets one text with the maximum of 256 characters from input and converts it to standard format based on the following rules and prints the final standardized text
- C++ Mini-Project: Human Resource Management Program
- Write a C++ program to Solve Quadratic equation
- C++ program for Calculation of the surface and the volume of a cone
- C++ Program to show Fibonacci Series
- C++ Program for Decimal to Hexadecimal Conversion
- C++ program to convert decimal number into binary
- C++ PROGRAM TO CHECK WHETHER A NUMBER IS NOT A PERFECT NUMBER OR NOT
- C++ program to find prime numbers in a given range
- C++ program to find Armstrong number
- C++ program to find prime number
- C++ program to convert a string into upper-case or lower-case
- C++ program to concatenate strings
- How to Run and install the mongo c++ drivers (MongoDB) On Ubuntu Linux
- How to Install Crypto++ Library with the Eclipse IDE on UBUNTU12.10 OS.
- Build and Run Sample Code Using Log4Cpp from Source Code on Ubuntu
- C++ counting the number of lines in a text file
- How do you implement the factorial function in C++
- C++ program to find HCF n LCM of two numbers
- The most elegant way to split a string in C++
- C++ Program for Printing 1 to 1000 without loop
- PASS BY REFERENCE C++ EXAMPLE
- C++ PROGRAM TO FIND WHETHER A NUMBER IS EVEN OR ODD
- C++ code to print all odd and even numbers in given range
- C++ Program to Check Palindrome Number
- C++ code to get sum of all odd numbers in given range
- C++ program to find ASCII Code for Characters and numbers
- Compiling and Integrating Crypto++ into the Microsoft Visual C++ Environment + Running Sample program
- Write a c++ program that calculates the average of three numbers
- C++ program compute hourly pay taking overtime into account
- C++ program to print 5 rows of 10 stars
- Write a C++ program that can print a temperature conversion
- Write a C++ program to construct a pyramid of stars
---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------
Newest 'log4cpp' Questions
c++ - getting started with log4cpp in ubuntu
C++ programming: A useful log4cpp example
log4cpp
Searches related to Log4Cpp
log4cpp tutorial
log4cxx
log4cpp category
log4cpp vs log4cxx
log4cpp appender
log4cpp documentation
log4cpp configuration file
log4cpp properties file example
0 comments:
Post a Comment