www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21416] New: betterC mode program with C++ interface fails to

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

          Issue ID: 21416
           Summary: betterC mode program with C++ interface fails to link
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: mobile majumdar.org.uk

import core.stdc.stdio : printf;

//extern (C++) abstract class A {
extern (C++) interface A {
    void sayHello();
}

extern (C++) class B : A {
    override void sayHello() {
        printf("hello\n");
    }
}

extern (C) void main() {
    scope b = new B;
    b.sayHello();
}

Above fails to link with DMD, works with LDC.

~/Software/dmd2/linux/bin64/dmd -betterC interfaces.d 
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld:
interfaces.o:(.data._D10interfaces1A11__InterfaceZ+0x0): undefined reference to
`_D14TypeInfo_Class6__vtblZ'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld:
interfaces.o:(.data._D10interfaces1B6__initZ+0x8): undefined reference to
`_D10interfaces1B7__ClassZ'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1

Tested on RHEL 7.9
DMD64 D Compiler v2.094.1

Replacing 'interface' with 'abstract class' appears to work in DMD, but this
should not be necessary since interface is extern (C++).

--
Nov 22 2020