www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Interop with C++ library - what toolchain do you use?

reply "Cliff" <cliff.s.hudson gmail.com> writes:
So I am trying to use a C++ library with D.  My toolchain is
currently Visual Studio 2013 with Visual D, using the DMD
compiler.  When trying to link, I obviously ran into the OMF vs.
COFF issue, which makes using the C++ library a bit of a trial to
say the least (I played around with some lib format converters
but perhaps unsurprisingly this led to somewhat unpredictable
behavior.)  I'd like to fix up my toolchain to avoid having this
issue.

For those of you who are on Windows and who do D and C++ interop,
what toolchain have you had success with?

Additionally, I have heard tell that D now allows calling C++
non-virtual class methods but I have not found documentation on
how to make this work (how do I define the C++ class layout in D
- I know how to do it for vtable entries but not non-virtual
methods.)  Pointers to docs or samples would be much appreciated.

Thanks!
Sep 17 2014
next sibling parent Jacob Carlborg <doob me.com> writes:
On 18/09/14 00:28, Cliff wrote:
 So I am trying to use a C++ library with D.  My toolchain is
 currently Visual Studio 2013 with Visual D, using the DMD
 compiler.  When trying to link, I obviously ran into the OMF vs.
 COFF issue
DMD has always produce COFF for Windows 64bit. Recently it also got support for COFF in 32bit. I don't think this has been released yet, but it's available in git master. -- /Jacob Carlborg
Sep 17 2014
prev sibling parent reply "Szymon Gatner" <noemail gmail.com> writes:
On Wednesday, 17 September 2014 at 22:28:44 UTC, Cliff wrote:
 So I am trying to use a C++ library with D.  My toolchain is
 currently Visual Studio 2013 with Visual D, using the DMD
 compiler.  When trying to link, I obviously ran into the OMF vs.
 COFF issue, which makes using the C++ library a bit of a trial 
 to
 say the least (I played around with some lib format converters
 but perhaps unsurprisingly this led to somewhat unpredictable
 behavior.)  I'd like to fix up my toolchain to avoid having this
 issue.

 For those of you who are on Windows and who do D and C++ 
 interop,
 what toolchain have you had success with?

 Additionally, I have heard tell that D now allows calling C++
 non-virtual class methods but I have not found documentation on
 how to make this work (how do I define the C++ class layout in D
 - I know how to do it for vtable entries but not non-virtual
 methods.)  Pointers to docs or samples would be much 
 appreciated.

 Thanks!
I am using Visual Studio 2012 (in x64 bit mode that is). Binary D distribution also comes with phobos64.lib that C++ executable has to link. With VisualD plugin you can just add D static library project to the solution and the link C++ exe to it. It is very easy to make back-and-forth function calls between C++/D. I recommend Adam Ruppe's excellent "D Cookbook" Integration chapter on the details on how to expose this for cross-lang usage. It does not all work correctly tho. I reported my issues on "learn" subforum but didn't get much help. In short: it seems not everything in D run-time (Phobos) gets properly initialized even after successful rt_init() call. In my case simple call to writeln() causes a crash because stdout is not properly initialized on D'd side. Happy hybridizing!
Sep 18 2014
parent "Cliff" <cliff.s.hudson gmail.com> writes:
On Thursday, 18 September 2014 at 08:27:07 UTC, Szymon Gatner
wrote:
 On Wednesday, 17 September 2014 at 22:28:44 UTC, Cliff wrote:
 So I am trying to use a C++ library with D.  My toolchain is
 currently Visual Studio 2013 with Visual D, using the DMD
 compiler.  When trying to link, I obviously ran into the OMF 
 vs.
 COFF issue, which makes using the C++ library a bit of a trial 
 to
 say the least (I played around with some lib format converters
 but perhaps unsurprisingly this led to somewhat unpredictable
 behavior.)  I'd like to fix up my toolchain to avoid having 
 this
 issue.

 For those of you who are on Windows and who do D and C++ 
 interop,
 what toolchain have you had success with?

 Additionally, I have heard tell that D now allows calling C++
 non-virtual class methods but I have not found documentation on
 how to make this work (how do I define the C++ class layout in 
 D
 - I know how to do it for vtable entries but not non-virtual
 methods.)  Pointers to docs or samples would be much 
 appreciated.

 Thanks!
I am using Visual Studio 2012 (in x64 bit mode that is). Binary D distribution also comes with phobos64.lib that C++ executable has to link. With VisualD plugin you can just add D static library project to the solution and the link C++ exe to it. It is very easy to make back-and-forth function calls between C++/D. I recommend Adam Ruppe's excellent "D Cookbook" Integration chapter on the details on how to expose this for cross-lang usage. It does not all work correctly tho. I reported my issues on "learn" subforum but didn't get much help. In short: it seems not everything in D run-time (Phobos) gets properly initialized even after successful rt_init() call. In my case simple call to writeln() causes a crash because stdout is not properly initialized on D'd side. Happy hybridizing!
Thanks guys. I do have that book, but I was unaware of the COFF capabilities of the 64-bit DMD, I'll take a look at it.
Sep 18 2014