export classes from DLLs
    John C 
    johnch_atms at hotmail.com
       
    Mon May  8 07:16:02 PDT 2006
    
    
  
Anyone ever got classes to export from DLLs correctly? I've searched the 
forum and it seems each effort has only got so far.
Using a factory method in the DLL works, but that's not what I'm trying 
to accomplish. If I try to create an instance in a program using the 
DLL, the compiler complains about an undefined symbol.
mydll.d implementation module
# // DllMain/gc_init etc omitted for brevity
#
# export class Dog {
# 	export static Dog create() {
# 		return new Dog;
# 	}
# 	char[] bark() {
# 		return "Woof";
# 	}
# }
mydll.di import module
# class Dog {
# 	static Dog create();
# 	char[] bark();
# }
mydll.def
# LIBRARY "mydll.dll"
# EXETYPE NT
# EXPORTS
Compile DLL and create import library
 > dmd mydll mydll.def
 > implib /system mydll.lib mydll.dll
program.d
# import mydll;
# void main() {
# 	// Dog dog = Dog.create(); // This works
#	Dog dog = new Dog; // This doesn't
# 	dog.bark();
# }
Compile program
 > dmd program mydll.lib
This produces the following error:
 > program.obj
 > Error 42: Symbol undefined __Class_7program3Dog
Adding __Class_7program3Dog to the EXPORTS list kills the error, but 
then the program throws an access violation.
When I compile classes into a static library (no DLL), this problem 
doesn't surface.
    
    
More information about the Digitalmars-d-learn
mailing list