c++ dll cross-compiler woes

Started by
3 comments, last by Enigma 21 years, 8 months ago
Hi, I''ve written a dll and can get it to link (explicitly at run time) to an executable, providing the dll and the executable are both compiled under the same compiler. I use abstract base classes to enable me to export classes from the dll and reference then in the executable easily. The problem is I''d quite like to be able to use one version of the dll with different compilers (currently I compile under Borland C++ 5.5 and minGW32). Unfortunately if I link a bcc32 compiled executable to a g++ compiled dll (or vice versa) I get an illegal operation first time I try to call a method in the dll from a pointer in the exe. At first I thought that this was probably due to differences in vtable formats but according to this article as MSDN, vtable memory layout is now a defacto standard. So, is what I want to do (one compiler exporting classes through a factory method, working with executables compiled under different compilers) possible in a dll? Is it time to look at COM? Is this even possible with COM? (Sorry if the last two are stupid questions - I''ve spent so much time looking at stuff about dll''s I haven''t done more than glance at articles about COM). Cheers, Enigma
Advertisement
I wouldn''t be sure that different compilers implement the vtable in the same way. Just because it''s a standard doesn''t mean everybody adheres to it.

This is the exact sort of problem that COM solves, so if interoperability is what you''re after, then go with COM.

If I had my way, I''d have all of you shot!

codeka.com - Just click it.
Thanks.

(More reading to do - great!)

Enigma
quote:Original post by Enigma
At first I thought that this was probably due to differences in vtable formats but according to this article as MSDN, vtable memory layout is now a defacto standard.


Standard for MS compiler, probably.

It is not possible to use dlls or C++ code with different compilers. To distinguish classes, the compiler prefix C++ classes with secret names in a process known as "Name mangling". This is unfortunately, a non standard process.
quote:Original post by Void
It is not possible to use dlls or C++ code with different compilers. To distinguish classes, the compiler prefix C++ classes with secret names in a process known as "Name mangling". This is unfortunately, a non standard process.


Actually, that''s not really the case here. If you''re using a pure virtual class as your base class, then all member functions are access through the vtable. If the vtable was standard, then you could do what Enigma is trying. However, I''d say that it''s generally not, and hence you need something like COM which enforces the calling conventions and vtable layout.

If I had my way, I''d have all of you shot!

codeka.com - Just click it.

This topic is closed to new replies.

Advertisement