www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Linux dll struct class etc

reply "Mineko" <uminekorox gmail.com> writes:
I can't remember whether or not I've asked this.. But either way, 
is it possible to "export" a class or a struct or something like 
you do with a windows dll with a linux shared library (dll)?
Jan 27 2014
next sibling parent "FreeSlave" <freeslave93 gmail.com> writes:
On Tuesday, 28 January 2014 at 02:40:40 UTC, Mineko wrote:
 I can't remember whether or not I've asked this.. But either 
 way, is it possible to "export" a class or a struct or 
 something like you do with a windows dll with a linux shared 
 library (dll)?
Do you mean loading classes and structs at runtime? You can do this just like in C++ - both library and application should know common base type. Then you need to resolve factory function from library. Factory function may create some derived class instance and return it as base, which known to application. But I'm not sure about GC - you will end up with two garbage collectors, as I presume. This solution also is only for classes, since structs don't support inheritance. Loading structs is more complicated and needs some reflection by hand, but still possible.
Jan 28 2014
prev sibling parent Benjamin Thaut <code benjamin-thaut.de> writes:
Am 28.01.2014 03:40, schrieb Mineko:
 I can't remember whether or not I've asked this.. But either way, is it
 possible to "export" a class or a struct or something like you do with a
 windows dll with a linux shared library (dll)?
You should be able to use classes from dynamic libraries just like you use classes from static libraries on linux. On windows the dll support is incomplete and it is not possible at the moment, to use a dll the same way as a static library. It is however possible to use factory functions on windows. But you will run into numerous other problems with windows dlls, so I don't recommend it. In case you are interrested read: http://wiki.dlang.org/DIP45 Kind Regards Benjamin Thaut
Jan 28 2014