How to make D resolve C++ symbols by mangling symbols with the Itanium ABI on Windows

thumbgun thumbgun07 at gmail.com
Mon Feb 26 17:23:32 UTC 2024


On Monday, 26 February 2024 at 15:49:40 UTC, user1234 wrote:
> On Monday, 26 February 2024 at 15:46:34 UTC, user1234 wrote:
>> On Monday, 26 February 2024 at 14:41:26 UTC, thumbgun wrote:
>>> On Monday, 26 February 2024 at 13:58:46 UTC, user1234 wrote:
>>>> On Monday, 26 February 2024 at 13:40:56 UTC, thumbgun wrote:
>>>>> The title wasn't very accurate as it isn't dmd that mangles 
>>>>> the names but my question still stands.
>>>>
>>>> Have you tried [pragma 
>>>> mangle](https://dlang.org/spec/pragma.html#mangle) ?
>>>
>>> I have seen it but it's not really what I need.
>>> [...]
>> Not even
>>
>> ```d
>> pragma(mangle, "?add@@YAHHH at Z")
>> extern(C++) int add(int lhs, int rhs);
>> ```
>>
>> ?
>
> Sorry, the one starting with a qmark is already what the D obj 
> thinks it has to be linked to. I meant
>
> ```d
> pragma(mangle, "_Zadd@@YAHHH at Z")
> extern(C++) int add(int lhs, int rhs);
> ```

The name mangling differences between the Itanium ABI and the 
MSVC ABI are more significant than just the prefix. I only 
mentioned that the prefixes are different to show that dmd was 
actually trying to link against symbols mangled by the MSVC ABI, 
not the Itanium one. If I used pragma mangle then I would have to 
manually translate each C++ function (signature) and struct/class 
to what the Itanium ABI would mangle them to which is very error 
prone and time consuming. I'm going to read the dmd source code - 
and maybe make a fork - because it apparently only tries to link 
against MSVC mangled symbols on Windows and not other platforms.


More information about the Digitalmars-d mailing list