www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Dynamically loading a D dynamic library from a c++ program

reply "Olivier Leduc" <account leduc.cc> writes:
Hello,

I need to use a C++ SDK to create a plugin an existing closed 
source c++ application and I would like to know if its possible 
to use D for that task.

Would is be possible to port the SDK header files and call the 
exposed functions inside the C++ program from a D dynamic library?

Is it possible at all?

Thank you very much!
Sep 26 2014
next sibling parent "Freddy" <Hexagonalstar64 gmail.com> writes:
On Friday, 26 September 2014 at 16:43:30 UTC, Olivier Leduc wrote:
 Hello,

 I need to use a C++ SDK to create a plugin an existing closed 
 source c++ application and I would like to know if its possible 
 to use D for that task.

 Would is be possible to port the SDK header files and call the 
 exposed functions inside the C++ program from a D dynamic 
 library?

 Is it possible at all?

 Thank you very much!
Try looking at this: http://dlang.org/dll-linux.html
Sep 26 2014
prev sibling next sibling parent "Freddy" <Hexagonalstar64 gmail.com> writes:
On Friday, 26 September 2014 at 16:43:30 UTC, Olivier Leduc wrote:
 Hello,

 I need to use a C++ SDK to create a plugin an existing closed 
 source c++ application and I would like to know if its possible 
 to use D for that task.

 Would is be possible to port the SDK header files and call the 
 exposed functions inside the C++ program from a D dynamic 
 library?

 Is it possible at all?

 Thank you very much!
and this: http://dlang.org/cpp_interface.html remember to be carefill with passing gc pointers
Sep 26 2014
prev sibling parent reply "John Colvin" <john.loughran.colvin gmail.com> writes:
On Friday, 26 September 2014 at 16:43:30 UTC, Olivier Leduc wrote:
 Hello,

 I need to use a C++ SDK to create a plugin an existing closed 
 source c++ application and I would like to know if its possible 
 to use D for that task.

 Would is be possible to port the SDK header files and call the 
 exposed functions inside the C++ program from a D dynamic 
 library?

 Is it possible at all?

 Thank you very much!
Yes, but it depends on the complexity of the headers. C++ templates aren't supported for example. There have been recent improvements to C++ compatibility, including namespace support, methods etc. and work is ongoing to get even more working. How large is the API? Sometimes the easiest approach is to create a simple extern "C" wrapper in C++ and then call that from D, as D has excellent C compatibility. See http://dlang.org/interfaceToC
Sep 26 2014
parent reply Jacob Carlborg <doob me.com> writes:
On 2014-09-26 21:52, John Colvin wrote:

 Yes, but it depends on the complexity of the headers. C++ templates
 aren't supported for example.
Templates are supported, if they're already instantiated. -- /Jacob Carlborg
Sep 27 2014
parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Saturday, 27 September 2014 at 09:19:57 UTC, Jacob Carlborg 
wrote:
 On 2014-09-26 21:52, John Colvin wrote:

 Yes, but it depends on the complexity of the headers. C++ 
 templates
 aren't supported for example.
Templates are supported, if they're already instantiated.
Sorry, yes, I should have clarified that.
Sep 27 2014