Thursday, August 29, 2013

Build Apache log4cxx on Microsoft Windows

  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 so that directory will look like    apache-log4cxx-0.10.0aprapr-util
  4. Rename apr-xxx to apr as shown above, rename apr-util-xxx to apr-util as shown above
  5. Open cmd.exe and type in:
  6. cd apache-log4cxx-0.10.0
  7. .\configure.bat
  8. Change to apr-util/include direcotry and open apu-hw in a texteditor of your choice
  9. Find the entry #define APU_HAVE_APR_ICONV, set it to 0 and save the file 
  10. 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  
  11. Change to log4cxx/projects directory and open log4cxx.dsw with MS VC++ 2012 ( I got Express version installed)
  12.  Answer Yes/OK to every question and build the solution. You are supposed to get about 111 Errors: "error C2252: an explicit instantiation of a template can only occur at namespace scope"
    1. Move all those LOG4CXX_LIST_DEF macros to before the class definition. in telnetappender.h you will also need to move the typedef that precedes this macro.
    2. 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) ex: change: LoggingEvent::KeySet set; to: KeySet set;
    3. in simpledtaeformat.h put the DEFINE after 'helpers' namespace definition, i.e.  namespace log4cxx
      {
              namespace helpers
              {
                namespace SimpleDateFormatImpl {
                  class PatternToken;
              }

              LOG4CXX_LIST_DEF(PatternTokenList, log4cxx::helpers::SimpleDateFormatImpl::PatternToken*);
  13. References:
    1. http://www.codeproject.com/Tips/492585/How-to-build-log4cxx-with-Visual-Studio-2010
    2.  
    3. http://blog.wupingxin.net/2011/09/11/build-log4cxx-with-visual-studio-2010/