[Issue 17081] New: Bodies in extern cpp functions in D files are not linked
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Jan 9 08:51:20 PST 2017
https://issues.dlang.org/show_bug.cgi?id=17081
Issue ID: 17081
Summary: Bodies in extern cpp functions in D files are not
linked
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: alexandru.razvan.c at gmail.com
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.
--
More information about the Digitalmars-d-bugs
mailing list