Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

log4cpp with eclipse

 
dushantha Rathnayake
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am new to c++. I want to develop a transaction management system. in that case i have to maintain log files. I got the an API for log file creating. It is log4cpp. I installed it. I am using eclipse indigo for c++. I try with fallowing example code.



I got this code from http://joysofprogramming.com/simple-log4cpp-example/

But in eclipse it's not work. And "log4cpp::Appender *appender = new log4cpp::FileAppender("FileAppender",LOGFILE);" line and other lines are indicate red colour. the compiler message is "undefined reference to `log4cpp::FileAppender::FileAppender(std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool,
unsigned int)'". Please help me. I don't know how to config this. the preprocessor including not indicate red colour.

Thank you.
 
Anand Hariharan
Rancher
Posts: 272
C++ Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The two word phrase "undefined reference" in your error message suggests that it is not the compiler but the linker that is reporting the stated error.

You have to setup your project within Eclipse or configure Eclipse itself so that it not only knows where the header files are (from what you are saying, Eclipse has that figured already), but also know where the LIB or SO files are, for it to link your executable to the needed binary libraries.

Hopefully someone who is knowledgeable in configuring Eclipse can show you how to do that.


Also, if I may point out, the code you have reproduced is considered poor C++ style. Java and C++ are different languages, and writing C++ in a style that is almost Java-like, is considered poor form. There is seldom a need to "new" any object in C++.


hope this helps,
- Anand
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic