Passing string from D to c++
John Colvin
john.loughran.colvin at gmail.com
Wed Jul 31 06:15:57 PDT 2013
On Wednesday, 31 July 2013 at 02:53:47 UTC, Walter Bright wrote:
> On 7/30/2013 3:01 PM, John Colvin wrote:
>> $ dmd -c -m64 inter.d
>> $ g++ -c -m64 inter.cpp -ointercpp.o
>> $ g++ inter.o intercpp.o -ointer -lphobos2
>> inter.o: In function `_Dmain':
>> inter.d:(.text._Dmain+0x48): undefined reference to
>> `printString(CppString*)'
>> collect2: error: ld returned 1 exit status
>
> You might want to look at the name mangling of the D
> printString vs the name mangling of the C++ one.
Woops, yeah that was never going to work.
However, I did come across something interesting:
gcc mangles std::string as "Ss", see here:
https://github.com/mirrors/gcc/blob/master/gcc/cp/mangle.c#L472
It also doesn't bother mangling the length for these special case
identifiers, e.g.
void printString(string * s, BLAHBLAH fdsa)
becomes
_Z11printStringPSs8BLAHBLAH
Any ideas how we can get around this? Some std c++ type
instrinsics in dmd?
More information about the Digitalmars-d
mailing list