Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C++

How to build log4cxx with Visual Studio 2010

5.00/5 (5 votes)
12 Nov 2012CPOL2 min read 30.9K  
This article should help you building log4cxx with Visual Studio 2010

Introduction

This article is a step-by-step tutorial about building the logging framework log4cxx from Apache based on my own experience. I've used version 0.10.0 of log4cxx when writing this article. 

Background

I tried to build log4cxx on many different ways like using the source out of the CVS repository and so on but with none of these ways I could get a working log4cxx library. I got a lot of help and ideas from another blog post located here. A big thank you to the author! I also posted this "article" as an answer on stackoverflow.com and you can find it here

Let's get started ... 

  1. Download the latest log4cxx package from here
  2. Download apr and apr-util ZIP packages from here
  3. Extract log4cxx, apr und apr-util to the same directory
  4. Rename the apr_VERSION and apr-util_VERSION folder to apr and apr-util resulting in a directory with three folder: apache-log4cxx-0.10.0, apr and apr-util 
  5. Change into the log4cxx directory and execute configure.bat
  6. Change to apr-util/include direcotry and open apu-hw in a texteditor of your choice
  7. Find the entry #define APU_HAVE_APR_ICONV, set it to 0 and save the file 
  8. Open apr_ldap.hw from the same directory and find the entry #define APR_HAS_LDAP, set it to 0 and save the file, too  
  9. Change to log4cxx/projects directory and open log4cxx.dsw with VS2010. Answer the converting prompts of VS2010 with yes/ok for each project (apr, apr-util, log4cxx, xml) 

OK ... if you hit build (F6) now then you will see around 2000 errors and that is where the interesting and hard part starts ... if it compiles fine then you're damn lucky guy! Wink | ;)  

  • Ctrl+F and find each entry of the "LOG4CXX_LIST_DEF" macro. You have to move these entries out of its related class and right before the same class. Sometimes you need to move a typedef too or add the class right before the macro. 

Some examples which should help you to understand what I mean:

C++
// telnetadapter.h
...
typedef log4cxx::helpers::SocketPtr Connection;
LOG4CXX_LIST_DEF(ConnectionList, Connection);
class LOG4CXX_EXPORT TelnetAppender : public AppenderSkeleton
...

// appender.h
...
class Appender;
LOG4CXX_PTR_DEF(Appender);
LOG4CXX_LIST_DEF(AppenderList, AppenderPtr);
class Layout;
typedef log4cxx::helpers::ObjectPtrT<Layout> LayoutPtr;
...
class LOG4CXX_EXPORT Appender :public virtual spi::OptionHandler
{
...

If the compiler complains about KeySet not being member of LoggingEvent, just remove the scope (since we moved the type to outside the class in the previous step, these types no longer are inside the class).

Example:

C++
// old
LoggingEvent::KeySet set;
// new
KeySet set;     
  • If the compiler complains about insert_iterator not being in the namespace std, add #include <iterator> to the include section of the source file
  • Last but not least, right-click on log4cxx project and select Add References and select the other 3 projects as reference   

That's it ... I hope this article can help someone who's struggling with the same problem! 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)