www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Dynamic Libaries in D

reply "Tim M" <a b.com> writes:
Can someone help me with dynamic libraries in d. I've seen this  
http://www.digitalmars.com/d/2.0/dll.html as an example of windows dll and  
a similar example of using tango here  
http://dsource.org/projects/tango/wiki/TutDLL but both say multiple  
threads not supported. How can I make a dll in d that supports multi  
threads.

I would also like to make linux modules so how can I do the initialization  
and finalization for those or can the compiler do it for me without coding  
it?
Oct 12 2008
parent reply Lars Ivar Igesund <larsivar igesund.net> writes:
Tim M wrote:

 Can someone help me with dynamic libraries in d. I've seen this
 http://www.digitalmars.com/d/2.0/dll.html as an example of windows dll and
 a similar example of using tango here
 http://dsource.org/projects/tango/wiki/TutDLL but both say multiple
 threads not supported. How can I make a dll in d that supports multi
 threads.
 
 I would also like to make linux modules so how can I do the initialization
 and finalization for those or can the compiler do it for me without coding
 it?

Unless you really need DLL's, and not only dynamic libraries - look into DDL. http://www.dsource.org/projects/ddl -- Lars Ivar Igesund blog at http://larsivi.net DSource, #d.tango & #D: larsivi Dancing the Tango
Oct 12 2008
next sibling parent reply BLS <nanali nospam-wanadoo.fr> writes:
Lars Ivar Igesund schrieb:
 Tim M wrote:
 
 Can someone help me with dynamic libraries in d. I've seen this
 http://www.digitalmars.com/d/2.0/dll.html as an example of windows dll and
 a similar example of using tango here
 http://dsource.org/projects/tango/wiki/TutDLL but both say multiple
 threads not supported. How can I make a dll in d that supports multi
 threads.

 I would also like to make linux modules so how can I do the initialization
 and finalization for those or can the compiler do it for me without coding
 it?

Unless you really need DLL's, and not only dynamic libraries - look into DDL. http://www.dsource.org/projects/ddl

production use. (Especially related to ix based systems) Windows DMD created DLL's are almost un-useable. No classes, no threads, no exeption handling. I am using DMD DLLs nevertheless (simply by creating wrappers functions around classes), but in general I would like to say: Using DMD shared libs is like bying tools from Shitty Butthead very LTD and I am afraid the situation will not change for quit a while. Bjoern
Oct 12 2008
parent reply Lars Ivar Igesund <larsivar igesund.net> writes:
BLS wrote:

 Lars Ivar Igesund schrieb:
 Tim M wrote:
 
 Can someone help me with dynamic libraries in d. I've seen this
 http://www.digitalmars.com/d/2.0/dll.html as an example of windows dll
 and a similar example of using tango here
 http://dsource.org/projects/tango/wiki/TutDLL but both say multiple
 threads not supported. How can I make a dll in d that supports multi
 threads.

 I would also like to make linux modules so how can I do the
 initialization and finalization for those or can the compiler do it for
 me without coding it?

Unless you really need DLL's, and not only dynamic libraries - look into DDL. http://www.dsource.org/projects/ddl

production use. (Especially related to ix based systems)

He was clearly talking about Windows dll's, and they will _never_ be production ready in D, whereas DDL is. In this particular case, it seems that *nix performance is irrelevant. -- Lars Ivar Igesund blog at http://larsivi.net DSource, #d.tango & #D: larsivi Dancing the Tango
Oct 12 2008
parent reply BLS <nanali nospam-wanadoo.fr> writes:
Lars Ivar Igesund schrieb:
 BLS wrote:
 
 Lars Ivar Igesund schrieb:
 Tim M wrote:

 Can someone help me with dynamic libraries in d. I've seen this
 http://www.digitalmars.com/d/2.0/dll.html as an example of windows dll
 and a similar example of using tango here
 http://dsource.org/projects/tango/wiki/TutDLL but both say multiple
 threads not supported. How can I make a dll in d that supports multi
 threads.

 I would also like to make linux modules so how can I do the
 initialization and finalization for those or can the compiler do it for
 me without coding it?

DDL. http://www.dsource.org/projects/ddl

production use. (Especially related to ix based systems)

He was clearly talking about Windows dll's, and they will _never_ be production ready in D, whereas DDL is. In this particular case, it seems that *nix performance is irrelevant.

Hi Lars, Quote Tim M. I would also like to make linux modules so how can I do the initialization and finalization for those ... End Quote. However, I use D DLLs by using the extern windows interface and the current behaviour is almost okay for me. But in case that I need extern D {} in order to create plugins for my D application .... you know. Borland's C++ compiler has support for that kind of shared libraries, so it is reasonable to ask : Why D has not. Kind regards, bjoen PS: will _never_ be production ready.. Why ?
Oct 12 2008
parent reply Lars Ivar Igesund <larsivar igesund.net> writes:
BLS wrote:
 
 Kind regards, bjoen
 PS: will _never_ be production ready.. Why ?

There are several reasons, most of which should be explained on the DDL pages. It has to do with exception handling, sharing of symbols, etc. -- Lars Ivar Igesund blog at http://larsivi.net DSource, #d.tango & #D: larsivi Dancing the Tango
Oct 12 2008
parent reply "Michael Robellard" <mrobellard ag.com> writes:
If your reason for writing a DLL is to interface into a 3rd party 
applpication. Which is the reason we are using DLLs in D then chances are 
the extern(Windows) or extern(C) style functions are what you want anyway. 
You can use D features behind your C style interfaces. We have successfully 
done this with implementing In process COM servers in D. If you want to just 
have nice dynamically loaded modules in your own native D app then from what 
I've seen DDL will be the right way to go when it's ready. If you want your 
application to be able to be extended by others, then you are back to DLLs 
since most people extending your application will probably not be using D.


"Tim M" <a b.com> wrote in message 
news:op.uixsjpl3jdp9fl tim-laptop.ssiltd.home...
 DDL looks nice but can I make DDLs in DLL format that can be loaded and 
 linked to an existing host application. I don't have access to the source 
 code for the host app. 

Oct 13 2008
parent reply Christopher Wright <dhasenan gmail.com> writes:
Tim M wrote:
 So do I just have to use C/C++ and is there any plans / current projects 
 that this may change in future?

No, you just have to do this: extern (Windows) { // The application calls this void someDllFunc () { // regular D code here } } void someNonDllFunc () { // The application doesn't see this. } extern (Windows) tells the compiler to disguise the functions so they look like regular C functions in the resulting object file. It doesn't change the meaning of any code inside.
Oct 13 2008
parent reply Mike Parker <aldacron gmail.com> writes:
Christopher Wright wrote:

 extern (Windows) tells the compiler to disguise the functions so they 
 look like regular C functions in the resulting object file. It doesn't 
 change the meaning of any code inside.

Not quite. That would be extern(C). Using the Windows version will give you a function with the stdcall calling convention, which changes the order in which parameters are passed on the stack in a function call. Not a good idea to use in the general case.
Oct 14 2008
parent Christopher Wright <dhasenan gmail.com> writes:
Mike Parker wrote:
 Christopher Wright wrote:
 
 extern (Windows) tells the compiler to disguise the functions so they 
 look like regular C functions in the resulting object file. It doesn't 
 change the meaning of any code inside.

Not quite. That would be extern(C). Using the Windows version will give you a function with the stdcall calling convention, which changes the order in which parameters are passed on the stack in a function call. Not a good idea to use in the general case.

Groovy, thanks. I use Linux, and even there I don't use extern; thus my ignorance.
Oct 14 2008
prev sibling next sibling parent "Tim M" <a b.com> writes:
DDL looks nice but can I make DDLs in DLL format that can be loaded and  
linked to an existing host application. I don't have access to the source  
code for the host app.
Oct 12 2008
prev sibling next sibling parent "Tim M" <a b.com> writes:
So do I just have to use C/C++ and is there any plans / current projects  
that this may change in future?


On Tue, 14 Oct 2008 01:26:43 +1300, Michael Robellard <mrobellard ag.com>  
wrote:

 If your reason for writing a DLL is to interface into a 3rd party
 applpication. Which is the reason we are using DLLs in D then chances are
 the extern(Windows) or extern(C) style functions are what you want  
 anyway.
 You can use D features behind your C style interfaces. We have  
 successfully
 done this with implementing In process COM servers in D. If you want to  
 just
 have nice dynamically loaded modules in your own native D app then from  
 what
 I've seen DDL will be the right way to go when it's ready. If you want  
 your
 application to be able to be extended by others, then you are back to  
 DLLs
 since most people extending your application will probably not be using  
 D.


 "Tim M" <a b.com> wrote in message
 news:op.uixsjpl3jdp9fl tim-laptop.ssiltd.home...
 DDL looks nice but can I make DDLs in DLL format that can be loaded and
 linked to an existing host application. I don't have access to the  
 source
 code for the host app.


Oct 13 2008
prev sibling parent "Tim M" <a b.com> writes:
Sorry if I haven't made myself clear enough. The main issue i'm worried  
about is memory leaks. I need to make sure the dll can be used by multiple  
threads and the gc be aware of each thread's memory.


On Tue, 14 Oct 2008 12:41:42 +1300, Christopher Wright  
<dhasenan gmail.com> wrote:

 Tim M wrote:
 So do I just have to use C/C++ and is there any plans / current  
 projects that this may change in future?

No, you just have to do this: extern (Windows) { // The application calls this void someDllFunc () { // regular D code here } } void someNonDllFunc () { // The application doesn't see this. } extern (Windows) tells the compiler to disguise the functions so they look like regular C functions in the resulting object file. It doesn't change the meaning of any code inside.

Oct 13 2008