Comment #0 by alexandru.razvan.c — 2017-01-09T16:51:20Z
While trying to interface C++ with D I noticed the bodies for external c++ functions in D files are not linked. For example I have the following files:
// D Source
import core.stdcpp.typeinfo;
import core.stdc.string:strcmp;
extern (C++) void fun(type_info ti)
{
assert(strcmp(ti.name(), "i") == 0);
}
// C++ Source
#include <typeinfo>
extern void fun(std::type_info *ti);
int main() {
fun(&typeid(int));
}
When trying to compile and link the 2 objects I get the following error: " undefined reference to `std::type_info::name() const'".
To solve this I edited druntime/src/core/stdcpp/typinfo.d and actually took the GNU libcpp implementation and translated it.
Now instead of "final const(char)* name();" we actually have a full implementation:
final const(char)* name()() const nothrow {
return _name[0] == '*' ? _name + 1 : _name;
}
Using this seems to solve the problem. I propose actually implementing all non-virtual functions from druntime/src/core/stdcpp in order to solve this.
Comment #1 by alexandru.razvan.c — 2017-01-09T17:07:06Z
IMPORTANT: A template function had to be used because regular functions would not be linked (notice "... const(char)* name()() ...")
Comment #2 by alexandru.razvan.c — 2017-01-13T12:44:46Z