Using C/C++-DLL in D

Andrej Mitrovic andrej.mitrovich at gmail.com
Mon Aug 26 16:33:37 PDT 2013


On 8/27/13, S0urc3C0de <s0urc3c0de at d.learn> wrote:
> Hello guys,
>
> I'm trying to use a C++-DLL in D.
> I compiled it via GCC, created a .lib-File with implib

I don't think you'll be able to match the name mangling, GCC might use
one convention, DMD another.

There was a pragma(mangle) feature introduced in git-head recently,
but it seems to be screwed up because if you set the calling
convention it will end up double-mangling the function. For example:

extern(C++) pragma(mangle, "_Z8printCppv") void printCpp();

This will still not link. The following will link, but it is not correct:

pragma(mangle, "_Z8printCppv") void printCpp();

The function is missing the calling convention, so you can't call it
without causing memory corruption.

I don't understand why this mangle feature was implemented this way.
The mangle pragma should be the last say on what the mangled name of a
symbol is, without adding additional mangling due to a calling
convention.

Anyway, the safest bet is to use C functions to interface with C++.


More information about the Digitalmars-d-learn mailing list