Let me first give brief information about my os:
My operating system is a full multiprocess multithread filesystem gui everything included filesystem, i have implemented the standard c headers. it can load and run every standard c ( example = nasm ) program.
my os supports dynamic linking against library files, the structure is basically similar with windows, library file exports some addresses ( with a special format ) and loader file imports something and os connects them together.
upto here everthing is good: i can very succesfully dynamically link "C" methods and variables.
my problem is:
>>> i cannot link a "C++" class and its member functions especially virtual methods and vtable of the class <<<
what i want is this: the executable file should only use the header file of the class, should be able to be linked to their methods, and the library file should have the methods and vtable of the class. and the executable should be able to override the virtual methods of the class.
this is not directly an os problem but i hope someone can give me some advise...
thanks.
Dynamic Linking to C++ vtable
Re:Dynamic Linking to C++ vtable
Exporting and importing classes from library's to executables is all done by the compiler right?
If a library exports a class, then the compiler exports functions / variables of a class the same way as it would export a simple function. But with some mangled export name.
I wrote some windows dll tool sometime ago that automaticly creates headers of VC++ dll's that export classes. Because of the mangled name you will know if the exported item is a function and how much parameters it has and what type the parameters are.
For example this a class that is imported from a dll in vc++.
The only thing you have to do in the dll is declare that the class has to be exported.
When importing in a executable you have to create a import library (for vc++ you have to do this) to define all imports of the library then you just declare the class header and say the compiler that the body is in some library.
For example a dll would define ENGINE_API _declspec(dllexport)
and use ENGINE_API as the class modifier.
Then the exe would do this.
If a library exports a class, then the compiler exports functions / variables of a class the same way as it would export a simple function. But with some mangled export name.
I wrote some windows dll tool sometime ago that automaticly creates headers of VC++ dll's that export classes. Because of the mangled name you will know if the exported item is a function and how much parameters it has and what type the parameters are.
For example this a class that is imported from a dll in vc++.
The only thing you have to do in the dll is declare that the class has to be exported.
When importing in a executable you have to create a import library (for vc++ you have to do this) to define all imports of the library then you just declare the class header and say the compiler that the body is in some library.
For example a dll would define ENGINE_API _declspec(dllexport)
and use ENGINE_API as the class modifier.
Then the exe would do this.
Code: Select all
#define ENGINE_API __declspec(dllimport)
#pragma message("Automatic link to Engine.lib")
#pragma comment(lib, "Engine.lib")
class ENGINE_API UTexRotator
{
private:
static class UClass PrivateStaticClass;
public:
static class UClass * __cdecl StaticClass(void);
static void * __cdecl operator new(unsigned int,class UObject *,class FName,unsigned long);
static void * __cdecl operator new(unsigned int,enum EInternal *);
static void __cdecl InternalConstructor(void *);
UTexRotator & operator=(UTexRotator const &);
UTexRotator(UTexRotator const &);
UTexRotator(void);
virtual class FMatrix * GetMatrix(float);
virtual void PostLoad(void);
virtual ~UTexRotator(void);
};
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Dynamic Linking to C++ vtable
Not quite. In the case of a static library, the importation is rather performed by the linker, which will retrieve the binary packages you need in the library and embed them in the executable.Kim wrote: Exporting and importing classes from library's to executables is all done by the compiler right?
In the case of a dynamic library, this is done by the loader or by the runtime itself.
Now, indeed, writing the list of symbols that need to be exported from the sourcecode into the produced binary and equivalently writing the symbols that need to be imported, including name mangling, etc. is performed by the compiler (so you better have to compile everything with the same compiler or with compilers that implements the same ABI).