[Issue 22323] New: Link error for virtual destructor of C++ class in DLL
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Sep 19 19:22:37 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22323
Issue ID: 22323
Summary: Link error for virtual destructor of C++ class in DLL
Product: D
Version: D2
Hardware: x86_64
OS: Windows
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: tim.dlang at t-online.de
A C++ class with virtual destructor in a DLL can't be used from D, because a
symbol is not found during linking.
/////////////// testdestructor.d /////////////////
extern(C++) class C
{
~this();
}
void main()
{
C o = new C;
}
///////////// testdestructorcpp.cpp //////////////
class __declspec(dllexport) C
{
public:
virtual ~C();
};
C::~C()
{
}
//////////////////////////////////////////////////
First I'm compiling a DLL from the C++ file:
cl /LD /nologo testdestructorcpp.cpp
Then I try to compile the D program using the DLL, which fails to link:
dmd -m64 testdestructor.d testdestructorcpp.lib
testdestructor.obj : error LNK2001: unresolved external symbol "public: virtual
void * __cdecl C::`scalar deleting destructor'(unsigned int)"
(??_GC@@UEAAPEAXI at Z)
testdestructor.exe : fatal error LNK1120: 1 unresolved externals
Error: linker exited with status 1120
It works using static linking.
In the forum I found a description of the same problem:
https://forum.dlang.org/thread/ijamdvhliodezmubgaxf@forum.dlang.org
--
More information about the Digitalmars-d-bugs
mailing list