www.digitalmars.com         C & C++   DMDScript  

D - Export/Import classes to/from a dll?

reply uwem <uwem_member pathlink.com> writes:
Hello!

A new year and a old question.
How i can export a complete class to a dll and how i can import this class from
the generated dll in a other program?
I generate a dll (set the class constructor and method to export, i have a def
file)-> dmd testdll.d testdll.def
I generate a lib file with the implib tool and use this file with the d compiler
-> dmd test.d testdll.lib
The error msg from OPTLINK:

hello.obj(hello)
Error 42: Symbol Undefined __Class_7testdll3Uwe
hello.obj(hello)
Error 42: Symbol Undefined _D7testdll3Uwe5_ctorFZC7testdll3Uwe

The class in the dll:
export class Uwe
{
public:
export this()
{
printf("Uwe::Uwe()\n");
}
export ~this()
{
printf("Uwe::~Uwe()\n");
}
export void doIt()
{
printf("Uwe::doIt()\n");
}
}

The test routine:

import testdll;

int main(char[][] args)
{
Uwe xx = new Uwe;

return 0;
}

I use windows.
Thanks in advance!

Bye
Uwe
Jan 09 2004
parent reply "Walter" <newshound digitalmars.com> writes:
You need to create an import library from the dll, and then link that into
the main program so the linker can resolve the symbols.

"uwem" <uwem_member pathlink.com> wrote in message
news:btm84a$bpn$1 digitaldaemon.com...
 Hello!

 A new year and a old question.
 How i can export a complete class to a dll and how i can import this class
from
 the generated dll in a other program?
 I generate a dll (set the class constructor and method to export, i have a
def
 file)-> dmd testdll.d testdll.def
 I generate a lib file with the implib tool and use this file with the d
compiler
 -> dmd test.d testdll.lib
 The error msg from OPTLINK:

 hello.obj(hello)
 Error 42: Symbol Undefined __Class_7testdll3Uwe
 hello.obj(hello)
 Error 42: Symbol Undefined _D7testdll3Uwe5_ctorFZC7testdll3Uwe

 The class in the dll:
 export class Uwe
 {
 public:
 export this()
 {
 printf("Uwe::Uwe()\n");
 }
 export ~this()
 {
 printf("Uwe::~Uwe()\n");
 }
 export void doIt()
 {
 printf("Uwe::doIt()\n");
 }
 }

 The test routine:

 import testdll;

 int main(char[][] args)
 {
 Uwe xx = new Uwe;

 return 0;
 }

 I use windows.
 Thanks in advance!

 Bye
 Uwe
May 19 2004
parent "David Barrett" <dbarrett quinthar.com> writes:
Uwe -- Did you ever get this to work?  Could you zip up your sample and post
a link to it?

"Walter" <newshound digitalmars.com> wrote in message
news:c8hh8b$21e5$1 digitaldaemon.com...
 You need to create an import library from the dll, and then link that into
 the main program so the linker can resolve the symbols.

 "uwem" <uwem_member pathlink.com> wrote in message
 news:btm84a$bpn$1 digitaldaemon.com...
 Hello!

 A new year and a old question.
 How i can export a complete class to a dll and how i can import this
class
 from
 the generated dll in a other program?
 I generate a dll (set the class constructor and method to export, i have
a
 def
 file)-> dmd testdll.d testdll.def
 I generate a lib file with the implib tool and use this file with the d
compiler
 -> dmd test.d testdll.lib
 The error msg from OPTLINK:

 hello.obj(hello)
 Error 42: Symbol Undefined __Class_7testdll3Uwe
 hello.obj(hello)
 Error 42: Symbol Undefined _D7testdll3Uwe5_ctorFZC7testdll3Uwe

 The class in the dll:
 export class Uwe
 {
 public:
 export this()
 {
 printf("Uwe::Uwe()\n");
 }
 export ~this()
 {
 printf("Uwe::~Uwe()\n");
 }
 export void doIt()
 {
 printf("Uwe::doIt()\n");
 }
 }

 The test routine:

 import testdll;

 int main(char[][] args)
 {
 Uwe xx = new Uwe;

 return 0;
 }

 I use windows.
 Thanks in advance!

 Bye
 Uwe
Jun 05 2004