logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curt Arnold <carn...@apache.org>
Subject Re: On Static Linking - Could not instantiate class [org.apache.log4j.ConsoleAppender]
Date Wed, 28 Nov 2007 21:38:07 GMT

On Nov 28, 2007, at 2:07 PM, Unnikrishnan Udinoor wrote:

> Hi,
>
> I am using log4cxx 0.9.7 version. On dynamically linking to the  
> log4cxx library my C++ application works fine with the logging.
>
> On changing the linking to static log4cxx , I get errors stating  
> that unable to instantiate the class.
>
> Can someone help me to fix this issue ? Thanks a lot in Advance.
>
> To be specific, this is the error I am getting.
>

Use of log4cxx 0.9.7 is discouraged.  Please consider moving to the  
SVN HEAD.  I remember a lot of pain with using log4cxx 0.9.7 from a  
static library and those issues should be fixed in the SVN HEAD.

The issue is due to the class registration information is only linked  
in when there is some explicit reference to the appender in the code.   
In this case, the linker did not see any reference to ConsoleAppender  
or RollingFileAppender when it linked your app, so those object files  
weren't linked into your app.  Since they weren't linked the static  
constructor that adds those classes to the list of available classes  
and so you get the class not found messages.  If you really want to  
use 0.9.7, you need to compel the linker to bring the appenders and  
layouts that you need into the app.  You could do that by having  
something (even unreachable code) in your app call  
ConsoleAppender::getStaticClass(), etc.

Mime
View raw message