Bug 17081 – Bodies in extern cpp functions in D files are not linked

Status
ASSIGNED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-01-09T16:51:20Z
Last change time
2024-12-13T18:51:21Z
Assigned to
Alexandru Razvan Caciulescu
Creator
Alexandru Razvan Caciulescu
Moved to GitHub: dmd#17787 →

Comments

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
Comment #3 by github-bugzilla — 2017-01-14T14:03:26Z
Commit pushed to master at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/e3e8b23401dd1a323f1f4567cef7612f74984bf9 Merge pull request #1736 from Darredevil/issue-17081 Workaround Issue 17081 - Bodies in extern cpp functions in D files are not linked
Comment #4 by github-bugzilla — 2017-01-16T23:24:51Z
Commit pushed to newCTFE at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/e3e8b23401dd1a323f1f4567cef7612f74984bf9 Merge pull request #1736 from Darredevil/issue-17081
Comment #5 by github-bugzilla — 2017-03-22T12:21:08Z
Commit pushed to stable at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/e3e8b23401dd1a323f1f4567cef7612f74984bf9 Merge pull request #1736 from Darredevil/issue-17081
Comment #6 by robert.schadek — 2024-12-13T18:51:21Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17787 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB