log4cxx for Win32 with VS2005

Yes, I wanted to have a uniform logging library for all my dev projects, after looking at log4cpp / log4cplus / log4cxx, I end up choosing log4cxx simply its obvious ability to use a external config file (just like log4j), which log4cpp and log4cplus is missing from.

Unfortunately using the library in Win32 is less then obvious.

The official site at http://logging.apache.org/log4cxx/ , provides “log4cxx-0.9.7″ but it comes with a warning: “At this point, log4cxx-0.9.7 is substantially out of date, has known serious deficiencies that have been resolved in the CVS, and should be avoided for new code.” *_*

After digging around, I downloaded the HEAD version, which suppose to be version 0.10.0, the source does not have a Visual Studio Project files, reading the installation instructions it says that I need ANT and bunch of other stuff to get it to build… fine… I can tolerate that…

After 3 hours of downloading and install the required package with exactly the same version of files required as stated in the installation guide and I figure, finally the moment of truth! (actually, later I found out its actually a beginning of another few hours of frustrations!)

The ant build went on, and its throwing all kind of error, and finally display a fail build status, I don’t understands, all the util are exactly the same version as request in the installation guide. After a few hours of search and debug, reading through the build script, nothing seems to help. Then a wild idea come up, “was it because there is a space in the folder name?“, I was building in my desktop, which gives a directory “C:\Document and Setting…” (you get the idea), I move the source folder to C:\tmp and start ant build there, and it runs!

Rebuilding with ant build, and it complain “Assertion failed, hunk …“, ok… I recognize that, it because of the sed util can’t handle CRLF in win32, so I went on writing a script, and change all CRLF in *.patch file into CR, that got rid of the error.

Rebuilding with ant build, building going on… splash BUILD FAILED! Apparently the unit test failed, did some search in the mailing list, nothing comes up…

Ok… I figure since ant build supports an option to build a VS2005 project file, which can be open with VS2005, it might be a better idea then relying on the Ant tool for the build.

Building the VS2005 project file gives a BUILD SUCCESS!

I open up the generated project file with VS2005, and start the compilation process, everything seems fine, until at the last bit of the compilation it splat me “fatal error LNK1104: cannot open file ‘.obj’ “. WTF is “.obj” ? I look into the vs project properties, no such thing in linker, and the path for link library is properly encase with double quote as well, every setting seems fine, but the darn library just wont compile… *_*

Ok… fine… ant tool still have another options to build a VC6 project file, oh hell why not? I’ve come this far… VC6 project file generation with ant tool yield BUILD SUCCESS (yes.. again). Load it up with VC6 and compile… Pronto! Success! I’ve finally got log4cxx binary!

I open up the VC6 project file with VS2005, and upgrade it to VS2005 compatible, and with my finger cross I hit compile… and it WORKS too!

Only problem now is that the ant build tool only generate a vs project file once per configuration, that mean if I want Debug Static library I have to build one file, Release Static library I have to build another, Debug Dynamic Link Library another one… so on and so forth…

I went on and build all the VC6 project file, rename it each time, since the build tool will overwrite its only use the same file name.

I upgrade all the VS6 project files to VS2005 compatible, and later hand edit them, so that it all fit nicely in a single solution, that will build both the Static and Dynamic version of log4cxx, Debug / Release build.

By the time I did that, its already the 4th day since I started of this log4cxx journey… pain pain pain… but it all came through…

To make your life less miserable, here’s the downloads:
VS2005 Binary Build of log4cxx v0.10.0 (out dated May 2007)
VS2005 Project + Source for log4cxx v0.10.0 (out dated May 2007)

VC6 Project + Source for log4cxx v0.10.0 (out dated May 2007)
(I’ve not try to compile this on a VC6 before, the purpose of me making this available is to allow you to convert the project file to other version of VS if you’re not using VS2005)

VC6 Binary Build + Source of log4cxx v0.10.0 (updated June 2008)
VC2008 Binary Build + Source of log4cxx v0.10.0 (updated June 2008)
(if you use other version of MSVC, then just get the VC6 package and upgrade the project files to your MSVC version)

Now please say thank you : )

Note:
To use the static link log4cxx library, the macro LOG4CXX_STATIC MUST be defined in your projects preprocessor, otherwise your compilation will suffer unresolved linking error.

Comments

  1. yeenfei says:

    Thanks man, after hours of frustration i decided to search the web and now it seem that ive made the right decision :)

  2. Isabel says:

    Tanks!

  3. Isabel says:

    Sorry, Thanks!

  4. Vijay says:

    Thanks, You have saved lot of my time.

  5. tilutza says:

    Thank you verry much.

    I’ve spend just 5-6 hours to compile, using directly VS 2008. You helped me much, now it works also with VS 2010.

  6. Jan says:

    Thanks! A lot! This will save me some time.

  7. Brandon says:

    Hey Merc,

    I have downloaded VS2005 Project + Source for log4cxx v0.10.0 because I am using VS2005.

    I hv complied ur log4cxx successfully, however, when i try to use the log4cxx in my application
    i run into apr.lib error link problem.

    Do you have any idea how to solve it?

    I have added the apr.lib,aprutil.lib and log4cxx.lib to the linker of my vs2005

  8. merc says:

    I’m not sure what could be the problem, but anyway, the 2005 package is pretty old as compare with what they have now. However, can you get the vc6 package and upgrade it with your vs2005 and see if that solve your problem?

    I have also heard that he new package in the official works better now compiling it in windows, maybe you can try that one as well if the vc6 package failed too.

  9. Brandon says:

    Hey Merc,

    May I know how do i upgrade the vc6 package?
    Where to download the new package?

    Thanks

  10. Arnaud says:

    Hi everyone,

    Brandon, if you get it to work with VS2005, I would be very interested in having an example.

    Tried it a while ago like 2 months and didn’t succeed, gonna give it another try this afternoon ; maybe I missed some steps..

    Anyway thanks Merc for helping us all :)

  11. merc says:

    Brandon, just download this http://www.dreamcubes.com/webdrive/log4cxx_win32/log4cxx-0.10.0-vc6-June2008.rar

    Open the project file with your vs2005, it’ll convert it to vs2005 project file.

    The official log4cxx site is here:http://logging.apache.org/log4cxx/index.html

  12. Arnaud says:

    Do you mean, you just open the mvc6-proj\log4cxx.sln solution file, and compile it again for every four options (debug static, debug shared, release static, release shared)?
    I guess this it, and then you just use the right log4cxx.lib (and optionally log4cxx.lib if using the shared .lib) to get it working. Am I right?

  13. Brandon says:

    Hey Merc,

    I have downloaded the log4cxx-0.10.0-vc6-June2008.rar however, when i try to open it in MS visual studio 2005 version 8.0.50727.762, using .net framework 2.0 sp2, it says the file is corrupted. Conversion fail.

    Any idea?

  14. merc says:

    did you open the file named “log4cxx.dsw” ?

  15. kitchener says:

    Thanks, you’ve saved my day

  16. billy says:

    Do we need the apr stuff in our projects or do we just need the lib4cx.lib/dll?

  17. billy says:

    Hi,

    Do I need to include all of apr.lib, aprutil.lib and xml.lib along with the obvious log4cxx.lib?

  18. merc says:

    yes… you’ll need all the lib for compilation, once compiled, you’ll only need to distribute it with the DLL files.

  19. billy says:

    Thank you. I also found that the static libs (those in the Debug_Static dir) are not true static libs .. I got tons of unresolved externals, which including a dll import reference in the error message. Switched to the Debug_Shared and the problem went away. Would like to use the static libs though.

  20. Brandon says:

    Hey Merc,

    I finally manage to get the libraries working.
    Downloaded VC6 Binary Build + Source of log4cxx v0.10.0.

    your Project works with VS2005

    THanks.

    Good job Merc.

    Just a note the libraries complied are separated into debug_shared and debug_static.
    If I am using dynamic linking I should use the debug_shared log4cxx.dll, correct?

    Lastly, I have download your log4cxx tutorial and try, but i realise the log4cxx generated a .1 file which stores all the logging information. May I know how to rename this file into something meaningful?

    THanks.

  21. BlueAngel says:

    Thank you very much for this post. This help me a lot.

    I have a problem and I hope to get some help here:
    I compiled everything static with VS 2010 Express but I was unable to compile anything shared due to an error wish VS, anyway I put the static libraries on my probject but every attend lead to a “undefined reference” to a lot of constructors and destructors of the library.

    I’m mostly sure I used the right compilers options.
    What can it be?
    I’m using the headers found on your project for including them on my program.

    I’m using Eclipse 3.5 with the lastest MinGW on Windows 7.

    Thank you for your time.

  22. merc says:

    I have not compile it with Eclipse before and I honestly do not know if the lib will work there or not. Why not try the new VS2010 Express? Its free : )

  23. merc says:

    which appender that you are using is generating the .1 file ?

  24. Sharanraj says:

    Thanks a lot :-) )))

  25. Herbert says:

    Merc, many thanks for all that work!
    As the SourceForge MSVC6.0 Project failed with VS2008, i googled for a solution and found your site which does not only explain the issue but also provide a ready to use solution for download.
    Great work!

  26. farsh says:

    Thank you Merc. For those looking to build this with VS2010 go here:
    http://comments.gmane.org/gmane.comp.apache.logging.log4cxx.user/2828

  27. Wuping Xin says:

    Thank you so much Merc! It is great help for me!

  28. JimmyTheOne says:

    Thanks Merc,
    I started to prepare log4cxx for one of my projects, then realised it was going to take longer to get the logger working than get the main project working.
    Great work, you saved the day and prevented me my losing any more hair :-)

  29. Jason says:

    Thank you thank you thank you thank you thank you thank you!

  30. michal says:

    hey man, thanx for your effort ! this is awesome… has helped me much!

  31. Ankhbayar says:

    Great, thank you very much!

  32. Andre says:

    thanks a lot for your work. this saved me a lot of time!

  33. brett says:

    Merc, thanks so much for sharing your work!

  34. Thanks a lot! It really helped me!

  35. Fred says:

    Thank you very much Merc! It worked fine with VS2008. This is a nice piece of work!

  36. Fred says:

    a small addition: for succesful linking adding ws2_32.lib and mswsock.lib was necessary

  37. Wei-Fang says:

    Thanks, pioneer!

  38. Jeremy Fox says:

    Wow thanks for doing all the hard work. This will save me a ton of time. Such a help

  39. Henry Ngenda says:

    Thanks Merc. Excellent work!. saved me alot of work.

  40. karthik says:

    Thank you. My time is saved.

  41. Robert says:

    My application crash on startup when I link with this log4cxx and is in release build. Is there anybody else out there that have experienced the same problem?

    The debug build works fine, and if I run the release build from the Visual Studio it doesn’t complain until shutdown, when it says that there is some heap corruption somewhere.

  42. merc says:

    it is possible that you are writing to memory location that is out of the bounds of a static array. Reason it works in debug compilation likely because in debug build there are some buffer/un-strip junk that in some coincident prevented the actual part that is essential from being overwritten. Anyway, it’s just a guess work, maybe this article will help:
    http://www.codeproject.com/Articles/38340/Immediate-memory-corruption-detection

    Also, I have not been updating this binary package for a while now since my old system are still running fine, the official site probably have newer version that has some new functionality that you might need.