I'm currently trying to call some C++ functions that were compiled by g++ (mingw). However g++ uses the Itanium ABI name mangling rules. dmd on Windows tries to link functions based on the MSVC name mangling rules. For example:
// add.cpp
int add(int lhs, int rhs)
{
return lhs + rhs;
}
// main.d
import std.stdio;
extern(C++) int add(int lhs, int rhs);
void main()
{
auto x = add(5, 6);
writeln(x);
}
// Command line
g++ add.cpp -c -o add.obj
dmd main.d add.obj
// Output
main.obj : error LNK2019: unresolved external symbol "int __cdecl add(int,int)"
(?add@@YAHHH@Z) referenced in function _Dmain
The prefix for MSVC symbols is '?' while the Itanium ABI's prefix is '_Z'. Is there any way I can make dmd link to symbols mangled according to the Itanium ABI's rules on Windows?