logo      
Custom Search

Re: Linking problems with Visual Studio 8

Date: December 20, 2006
From: "Charles Tuckey" <charles@xxxxxxxxx>

In-reply-to: <a4ff0d310612191509y67f80f7fh891212371bc68c6@xxxxxxxxxxxxxx>
References: <a4ff0d310612191509y67f80f7fh891212371bc68c6@xxxxxxxxxxxxxx>

Problem solved. Some of the log4cxx include files are auto generated.
On the Windows platform, I was using a set of include files I had
copied over from Linux. The log4cxx.h from Linux specified a  UTF8
logchar, the proper one from Windows specifies a wchar logchar.

I was using the Windows include files to build the log4cxx shared
library, and the Linux include files to build my library. This meant
anything with a LogString had a type mismatch.

Thanks for listening.

charlie

On 12/19/06, Charles Tuckey <charles@xxxxxxxxx> wrote:
Hi,

I built the log4cxx library on WXP SP2 with no problems. But when I
try to link a very simple dll to it I get an unresolved symbol
problem. My problem is very similar to Sorin Popa (Nov 28 email). I
have some ideas on what the problem might be but I am not a very
strong C++ programmer and I have little experience on Windows as well
so I haven't been able to solve this. Details are below. Any help, or
gentle nudge in the right direction, would be greatly appreciated.

1) log4cxx build
- I'm using the HEAD from Nov. 13m 2006
- I built according to the instructions in INSTALL except:
  - I  added unxutils to my path so I could access the 'patch' command
  - I ran setenv.cmd from Microsoft Platform SDK for Windows Server 2003 R2 dir
- my command line was 'ant build'
- I ended up with a debug lib

2) my library
- the source consists of two files: EngineAppender.h & EngineAppender.cpp
EngineAppender.h listing:
#include <log4cxx/appenderskeleton.h>
#include <log4cxx/spi/loggingevent.h>
#include <log4cxx/helpers/pool.h>

class EngineAppender : public log4cxx::AppenderSkeleton {
  protected :
     void append(const log4cxx::spi::LoggingEventPtr& event,
                        log4cxx::helpers::Pool& p);
  public :
     void close();
     bool requiresLayout() const;
};

EngineAppender.cpp listing:
#include "EngineAppender.h"
#include "log4cxx/spi/loggingevent.h"

void EngineAppender::append(const log4cxx::spi::LoggingEventPtr& event,
                                            log4cxx::helpers::Pool& p) {
        event->getLoggerName();
}
void EngineAppender::close() { }
bool EngineAppender::requiresLayout() const {return 0;}

- before building I ran setenv.cmd to set up my environment
- then I ran
#include "EngineAppender.h"
#include "log4cxx/spi/loggingevent.h"

void EngineAppender::append(const log4cxx::spi::LoggingEventPtr&
event, log4cxx::helpers::Pool& p) {
        event->getLoggerName();
}

void EngineAppender::close() { }

bool EngineAppender::requiresLayout() const {
        return 0;
}

- I create the library with these two commands:
cl -DWIN32 -D_WIN32 -EHsc -Ilog4cxx/include -c EngineAppender.cpp
link -DLL EngineAppender.obj -out:test.dll log4cxxd.lib

It fails with the error:
EngineAppender.obj : error LNK2019: unresolved external symbol "public: class st
d::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >
const __thiscall log4cxx::spi::LoggingEvent::getLoggerName(void)const " (?getLog
gerName@LoggingEvent@spi@log4cxx@@QBE?BV?$basic_string@DU?$char_traits@D@std@@V?
$allocator@D@2@@std@@XZ) referenced in function "protected: virtual void __thisc
all EngineAppender::append(class log4cxx::helpers::ObjectPtrT<class log4cxx::spi
::LoggingEvent> const &,class log4cxx::helpers::Pool &)" (?append@EngineAppender
@@MAEXABV?$ObjectPtrT@VLoggingEvent@spi@log4cxx@@@helpers@log4cxx@@AAVPool@34@@Z
)

3) My troubleshooting
- In the log4cxx library the mangled name for getLoggerName is:
?getLoggerName@LoggingEvent@spi@log4cxx@@QBE?BV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@XZ

This differs from the name the linker is looking for in the
parameterized type to basic_string. The log4cxx library has _W (wchar)
and my linker is looking for a char type (D). (Sorin's linker was
looking for an unsigned short, G).

Even though I thought it would have no effect since I am using VC 8 I
tried compiling with the -Zc:wchar_t option. No change.

So, I'm stumped. How do I make my object file compile using
basic_string<wchar>? I cannot find anything on goolge (that I can
understand) that would help me solve this.

Thanks for your help,
charlie



--
Regards,
   Charlie




Custom Search