How I can add log4cplus Framework to an existing project under VC++ ? When i try to do it I receive linker errors. I don't how to fix it. Thanks herzl
-
4Error.doShow.. you need to show the linker errors you get. Undefined? Cannot find include files? – Max Feb 20 '11 at 12:59
2 Answers
In your project configuration, you need to add the library to your linker settings. While I'm here, though, let me briefly evangelize the google-glog library (which Google uses for its own logging). You can find documentation for it on the Google Logging (GLog) Documentation page. Unlike Log4Cxx, which requires you to create various loggers all over the place, GLog is a little bit simpler to use. Example:
LOG(ERROR) << "An error occurred.";
LOG(DFATAL) << "This will kill the program in debug mode, but not regular mode.";
It's not necessary to instantiate "LOG", "ERROR", or "DFATAL" in the above. They are just there. It also includes some various assertion macros like CHECK, CHECK_NOTNULL, etc. which will check that a particular condition is true, and then LOG(FATAL) with a useful error message if it is the case.

- 93,612
- 16
- 138
- 200
-
In each calling to log operation this open file and close it. – herzl shemuelian Feb 21 '11 at 07:56
-
I haven't looked at the implementation, but that wouldn't be surprising. The worst thing when debugging is for an application to crash before its logs have been flushed. If one logs an ERROR, typically it is important enough that it is worth the explicit flush (and possibly an explicit fsync, as well). One can always use LOG_EVERY_N to reduce the logging frequency. And one can use a lower logging level such as LOG(INFO) and VLOG for unimportant-ish things. – Michael Aaron Safyan Feb 24 '11 at 10:03
I started evaluating log4cplus yesterday. I downloaded and built the library under VC2010 without any trouble. But when you have to link with your own code, it becomes a little tricky since the lib and dll files are scattered all over. I edited the property pages to alter the output directory so that I can find all the debug libs and dlls in one directory and release libs and dlls in another.
Also, for the log4cplus_dll library, name of the lib is different from the dll. I fixed that in the project property. Now I am able to link properly and run it.

- 1,627
- 2
- 18
- 34