Click here to Skip to main content
15,867,771 members
Articles / Programming Languages / C++
Tip/Trick

How to build log4cxx with Visual Studio 2010

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
12 Nov 2012CPOL2 min read 29.8K   9   8
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)


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionVisual Studio 2015 Pin
deatc15-Nov-16 6:46
deatc15-Nov-16 6:46 
QuestionLink error Solution? Pin
Member 1223033929-Dec-15 6:36
Member 1223033929-Dec-15 6:36 
QuestionLog4Cxx link error Pin
JeCheng11-Jul-15 7:11
JeCheng11-Jul-15 7:11 
AnswerRe: Log4Cxx link error Pin
a.e.h.8-Dec-15 8:44
a.e.h.8-Dec-15 8:44 
I get this too. Haven't found a fix yet.
AnswerRe: Log4Cxx link error Pin
Member 1223033926-Dec-15 23:41
Member 1223033926-Dec-15 23:41 
Questionstd::length_error in Debug builds Pin
User 102345631-Mar-14 7:20
User 102345631-Mar-14 7:20 
QuestionDanke Pin
Member 999955018-Mar-14 3:12
Member 999955018-Mar-14 3:12 
QuestionWhat about c++ builder ? Pin
Member 997458230-Jul-13 2:29
Member 997458230-Jul-13 2:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.