help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dynamic_cast problem


From: KeithO
Subject: Re: dynamic_cast problem
Date: Sun, 4 Jul 2004 12:56:04 +0100

The problem I am facing is not with dynamic loading of the library but with
dynamic_cast. The test.app has retrieved a valid DestinationImpl *, I know
it's valid as I can call pDestImp->getName() which returns
"Destination_tib". The problem comes when I try to dynamically cast to a
Destination_tib *, which fails.
Destination_tib * p = dynamic_cast<Destination_tib *>(pDestImpl);

Interestingly if I compile the test.app with gcc rather than g++ I get the
following link errors:
gcc3 -g  -Wall -I. -L. test.cpp -ldl -o test
/tmp/cc1brGwj.o: In function `main':
test.cpp:20: undefined reference to `__dynamic_cast'
test.cpp:9: undefined reference to `vtable for
__cxxabiv1::__si_class_type_info'
test.cpp:9: undefined reference to `vtable for
__cxxabiv1::__class_type_info'
test.cpp:10: undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
Why would it link with g++3 and not gcc3

Keith

"Rolf Magnus" <ramagnus@t-online.de> wrote in message
news:cc8hel$eg4$03$1@news.t-online.com...
> Ulrich Eckhardt wrote:
>
> > KeithO wrote:
> >> extern "C" DestinationImpl * getDestinationImpl(void);
> >
> >>     MODULE_HANDLE fn = (void *(*)())dlsym(hdll,
> >>     "getDestinationImpl");
> >
> > The functiontypes don't match. Further, I'd use a typedef(at least for
> > your readers).
>
> He does use a typedef, but for some reason, he doesn't use it for the
> cast, but only for defining fn.
>
> > Also consider that this cast is not valid, neither in C
> > nor C++. Take a look at comp.lang.c++.moderated, there was a thread
> > started by me that explains the details.
>
> I don't think you can use a valid cast in this place at all. That's just
> a problem with dlsym.
>
> > BTW: why pass around a void*? Your lib could as well declare the
> > struct class and export a function returning a pointer to it.
>
> That's what the lib is actually doing. The OP is just interpreting that
> pointer as a void* in the main program and then converting that "back"
> into a DestinationImpl*.
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]