Request Assistance Calling D from C++: weird visibility issue inside struct and namespace

Andrew Edwards edwards.ac at gmail.com
Wed Nov 8 07:46:43 UTC 2017


On Wednesday, 8 November 2017 at 07:06:39 UTC, Nicholas Wilson 
wrote:
> On Wednesday, 8 November 2017 at 06:34:27 UTC, Andrew Edwards 
> wrote:
>> I'm having a little bit of problem calling D code from C++ and 
>> would appreciate some assistance. First, given the following 
>> C++ program wich compiles, links, and runs without any problem:
>
> Try using `nm` on the C++ object to find out what it thinks the 
> mangling should be.
> Check that against the mangling DMD produces.

Tried it, and it works.

Solution:

     nm dexample | grep foo -> returns the __C++__mangling

Use it to define the function as such:

     pragma(mangle, "__C++__mangling")
     extern (C++) void foo(const char* str) {
         // doing great things;
     }

Thank you so much.

-Andrew



More information about the Digitalmars-d-learn mailing list