Bug 22319 – vtable not exported for extern(C++) class under Linux

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-09-18T12:47:33Z
Last change time
2024-12-13T19:18:31Z
Keywords
C++
Assigned to
No Owner
Creator
Tim
Moved to GitHub: dmd#19985 →

Comments

Comment #0 by tim.dlang — 2021-09-18T12:47:33Z
A class without constructor can't be created under Linux from C++ if it is defined in D. //////////////// testvbtl.d ////////////////// extern(C++) class C { int f() { return 1; } } extern(C++) C createC(); void main() { C c = new C; assert(c.f() == 1); } //////////////// testvbtl.cpp //////////////// class C { public: virtual void f(); }; C *createC() { return new C; } ////////////////////////////////////////////// % g++ -c testvbtl.cpp -o testvbtl.cpp.o % dmd -L-lstdc++ testvbtl.d testvbtl.cpp.o /usr/bin/ld: testvbtl.cpp.o: warning: relocation against `_ZTV1C' in read-only section `.text._ZN1CC2Ev[_ZN1CC5Ev]' /usr/bin/ld: testvbtl.cpp.o: in function `C::C()': testvbtl.cpp:(.text._ZN1CC2Ev[_ZN1CC5Ev]+0xb): undefined reference to `vtable for C' /usr/bin/ld: warning: creating DT_TEXTREL in a PIE collect2: error: ld returned 1 exit status Error: linker exited with status 1 The C++ part seems to need the symbol _ZTV1C with the virtual table, but the D part does not export it using this name.
Comment #1 by robert.schadek — 2024-12-13T19:18:31Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19985 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB