Compiling a mixed D and C++ project?

Manu turkeyman at
Mon Sep 2 20:29:58 UTC 2019

On Mon, Sep 2, 2019 at 12:55 PM Kyle De'Vir via Digitalmars-d
<digitalmars-d at> wrote:
> Here is my code, by the way:
> main.d
> TestApplication.h
> TestApplication.cpp

It looks like you're mixing up C++ classes and D structs, which are
completely different.
You shouldn't use extern(C), you should use extern(C++), and then
you'll get proper errors when you fail to get the types correct,
otherwise you'll continue to get surprising crashes like this when you
match the types wrong.

My guess is that maybe the problem starts here:

    extern __gshared struct QtApplication;
    QtApplication* TestApplication_Init();

QtApplication is a class with a vtable, so it should be `extern(C++)
class` and definitely not `struct`.
In D, classes are reference types, so you don't use '*' as in
`QtApplication*` with classes, just `QtApplication`.

Also, that's just a weird line; what does it mean? I haven't seen an
`extern __gshared` struct before... but I think you mean:
  extern(C++) class QtApplication;
  QtApplication TestApplication_Init();

More information about the Digitalmars-d mailing list