Issue 21416 - betterC mode program with C++ interface fails to link
Summary: betterC mode program with C++ interface fails to link
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 major
Assignee: No Owner
URL:
Keywords: betterC, C++, pull
Depends on:
Blocks:
 
Reported: 2020-11-22 23:23 UTC by Dibyendu Majumdar
Modified: 2022-05-10 07:13 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Dibyendu Majumdar 2020-11-22 23:23:07 UTC
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++).
Comment 1 Richard (Rikki) Andrew Cattermole 2021-08-10 16:13:23 UTC
Minified further:

extern(C) void main() {}

extern(C++) interface IEntry {
}

extern(C++) class MyEntryInfo : IEntry {
}

This is known to work for ldc 1.26.0.

The __ClassZ error was introduced between dmd 2.094.0 and 2.097.2.
Comment 2 Dlang Bot 2022-05-05 13:13:42 UTC
@RazvanN7 created dlang/dmd pull request #14075 "Fix Issue 21416 - betterC mode program with C++ interface fails to link" fixing this issue:

- Fix Issue 21416 - betterC mode program with C++ interface fails to link

https://github.com/dlang/dmd/pull/14075
Comment 3 Dlang Bot 2022-05-10 07:13:11 UTC
dlang/dmd pull request #14075 "Fix Issue 21416 - betterC mode program with C++ interface fails to link" was merged into master:

- 2e6ffd14eba3352d36642d8ffab012e8f1787673 by RazvanN7:
  Fix Issue 21416 - betterC mode program with C++ interface fails to link

https://github.com/dlang/dmd/pull/14075