www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22319] New: vtable not exported for extern(C++) class under

https://issues.dlang.org/show_bug.cgi?id=22319

          Issue ID: 22319
           Summary: vtable not exported for extern(C++) class under Linux
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: tim.dlang t-online.de

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.

--
Sep 18