Interop with C++ library - what toolchain do you use?

Szymon Gatner via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 18 01:27:05 PDT 2014


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!


More information about the Digitalmars-d-learn mailing list