Interfacing D with C and C++
bachmeier via Digitalmars-d
digitalmars-d at puremagic.com
Sat Aug 23 19:32:20 PDT 2014
On Saturday, 23 August 2014 at 22:46:11 UTC, Scott Wilson wrote:
> Hello, world. Brand new poster here though I posted similar
> messages in other language forums. I hope this is the right
> place to ask because my question is half about existing stuff
> and half about prospective work.
>
> I am considering starting with D amid a C++ code base. New D
> code would need to somehow integrate with the existing C++
> code. The C++ code is the expected melange of free functions,
> classes, what have you and uses STL and Boost (also other libs
> less prominently). Allow me to ask:
>
> 1. What is the current support for calling C/C++ free functions
> from D? What level of mangling is supported? What data types
> can be passed without translation from D to C/C++?
>
> 2. How about template functions? Is it possible to call a C++
> template function from D?
>
> 3. How can a C++ object be used from D? Can C++ methods be
> called from D? The question applies to value types - no
> virtuals - and polymorphic types with virtuals, inheritance
> etc. And of course simple C structs.
>
> 4. How about template objects? One issue is that many C++
> interfaces pass std::string and std::map<..., ...> as
> parameters. How feasible is to manipulate such objects in D?
>
> 5. How about the other way? Can a C/C++ function call a D
> function?
>
> I would appreciate any pointers you have to how-to materials.
> In equal measure I am interested in plans to address such
> issues in the foreseeable future. Thankyou.
>
>
> Scott
I'm only able to answer (5). I regularly create shared libraries
on Linux and call them from C. It's very simple (for what I've
done anyway). The info on this page http://dlang.org/interfaceToC
should get you started. http://dlang.org/dll-linux.html#dso9
explains compilation.
http://forum.dlang.org/group/digitalmars.D.learn is a friendly
place to ask if you've got questions.
This recent post
http://forum.dlang.org/post/fxdqpmfcbskvtcafzfcp@forum.dlang.org
and some of the replies explain where things are headed and
difficulties with C++ interoperability.
More information about the Digitalmars-d
mailing list