April 28, 2024, 11:43:39 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Cross Language Class Library

Started by Rock Ridge Farm (Larry), August 12, 2006, 04:49:59 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rock Ridge Farm (Larry)

This may be another obvious stupid question but -----
I know we can with some effort use windoze class libraries.
Can I call a Aurora class lib (compiled as a dll I guess) from a Microsoft C/C++ or other compiler?

Ionic Wind Support Team

Nope.  All compilers impliment there own version of method name mangling.  You can't use class libraries written VC++ with any other compiler, sometimes not even different versions of the same compiler.

The reason being is a method is a function (subroutine if you prefer the name).  And assemblers and linkers know nothing about OOP.  OOP is done completely in the compiler so it has to come up with a unique name for every method used by every class. 

For instance with compilers that allow overloading of methods there is a distinct name generated for each overload.  C++ uses letters to denote different paramaters.  Let's say you had two overloaded methods of a class named MyClass. C++ code here:

class MyClass
{
public:
   int Foo(float c);
   int Foo(double d, int e);
};

int MyClass::Foo(float c)
{
}

int MyClass::Foo(double d, int e)
{
}

So here we have two methods with the same name, taking different parameters.  You can't link object files if there are naming collisions, even the assembler will complain about duplicates.  So C++ compilers create the 'real' function name using a mangling template.  Each template is different from compiler maker to compiler maker.  For sake of discussion we'll say out hypothetical C++ compiler uses a template of:

function@classname?parameters

Each parameter type is given a letter code.  A = byte, B=word, C=int, D=int64, E = float, F= double, etc.  So when the code above is compiled the method names look like this to the assembler and linker:

Foo@MyClass?E
Foo@MyClass?FC

However another makers C++ compiler might use a template that makes the function names:

_MyClass@Foo??Z?W
_MyClass@Foo??XW?W

Which is why it's hard to use a class library written by a Microsoft compiler in say GCC.

Ionic Wind Support Team