digitalmars.D.learn - compile error while use `extern(C++, class)`
- mogu (10/10) Aug 17 2016 From spec (Interfacing to C++)
- Lodovico Giaretta (8/18) Aug 18 2016 Which kind of error? An error message by the compiler? One by the
- mogu (10/12) Aug 18 2016 Compiler Error exactly. The minimal code is(dmd or ldc2 in ubuntu
- Lodovico Giaretta (6/20) Aug 18 2016 Which compiler version are you using? On DMD 2.071.0 this does
- pineapple (4/26) Aug 18 2016 Wouldn't this be more syntactically consistent if it were "Cpp"
- Johan Engelen (5/18) Aug 18 2016 Note: this does work with LDC 1.1.0 even though it is based on
- Lodovico Giaretta (6/13) Aug 18 2016 Well, LDC 1.1.0 is based on DMD 2.071.1, while I tested the above
- mogu (4/20) Aug 18 2016 No, i'm using the newest version of dmd/ldc2 (2.071.1/1.0.0)
From spec (Interfacing to C++) https://dlang.org/spec/cpp_interface.html: ``` When mapping a D class onto a C++ struct, use extern(C++, struct) to avoid linking problems with C++ compilers (notably MSVC) that distinguish between C++'s class and struct when mangling. Conversely, use extern(C++, class) to map a D struct onto a C++ class. ``` But this compiles error. Please help, thanks.
Aug 17 2016
On Thursday, 18 August 2016 at 01:06:29 UTC, mogu wrote:From spec (Interfacing to C++) https://dlang.org/spec/cpp_interface.html: ``` When mapping a D class onto a C++ struct, use extern(C++, struct) to avoid linking problems with C++ compilers (notably MSVC) that distinguish between C++'s class and struct when mangling. Conversely, use extern(C++, class) to map a D struct onto a C++ class. ``` But this compiles error. Please help, thanks.Which kind of error? An error message by the compiler? One by the linker? The compiler crashes? If you don't tell us what happens exactly, and a simple example code that triggers the issue, we don't know what to do. If your codebase is big and you don't manage to reduce it to a couple lines to show the error, you can try dustmite [1]. [1] https://github.com/CyberShadow/DustMite/wiki
Aug 18 2016
On Thursday, 18 August 2016 at 10:45:14 UTC, Lodovico Giaretta wrote:Which kind of error? An error message by the compiler? One by the linker? The compiler crashes?Compiler Error exactly. The minimal code is(dmd or ldc2 in ubuntu 16.04 lts): ``` extern (C++, struct) class A {} ``` Error: identifier expected for C++ namespace found 'struct' when expecting ')' declaration expected, not ')'
Aug 18 2016
On Thursday, 18 August 2016 at 11:11:10 UTC, mogu wrote:On Thursday, 18 August 2016 at 10:45:14 UTC, Lodovico Giaretta wrote:Which compiler version are you using? On DMD 2.071.0 this does not work. On nightly build it compiles without errors. So probably it is a feature that is present, but didn't ship yet. I suggest you download the latest beta or a nightly build from the site.Which kind of error? An error message by the compiler? One by the linker? The compiler crashes?Compiler Error exactly. The minimal code is(dmd or ldc2 in ubuntu 16.04 lts): ``` extern (C++, struct) class A {} ``` Error: identifier expected for C++ namespace found 'struct' when expecting ')' declaration expected, not ')'
Aug 18 2016
On Thursday, 18 August 2016 at 11:43:03 UTC, Lodovico Giaretta wrote:On Thursday, 18 August 2016 at 11:11:10 UTC, mogu wrote:Wouldn't this be more syntactically consistent if it were "Cpp" instead of "C++"?On Thursday, 18 August 2016 at 10:45:14 UTC, Lodovico Giaretta wrote:Which compiler version are you using? On DMD 2.071.0 this does not work. On nightly build it compiles without errors. So probably it is a feature that is present, but didn't ship yet. I suggest you download the latest beta or a nightly build from the site.Which kind of error? An error message by the compiler? One by the linker? The compiler crashes?Compiler Error exactly. The minimal code is(dmd or ldc2 in ubuntu 16.04 lts): ``` extern (C++, struct) class A {} ``` Error: identifier expected for C++ namespace found 'struct' when expecting ')' declaration expected, not ')'
Aug 18 2016
On Thursday, 18 August 2016 at 11:43:03 UTC, Lodovico Giaretta wrote:On Thursday, 18 August 2016 at 11:11:10 UTC, mogu wrote:Note: this does work with LDC 1.1.0 even though it is based on DMD 2.071. https://github.com/ldc-developers/ldc/releases/tag/v1.1.0-beta2Compiler Error exactly. The minimal code is(dmd or ldc2 in ubuntu 16.04 lts): ``` extern (C++, struct) class A {} ``` Error: identifier expected for C++ namespace found 'struct' when expecting ')' declaration expected, not ')'Which compiler version are you using? On DMD 2.071.0 this does not work.
Aug 18 2016
On Thursday, 18 August 2016 at 16:19:41 UTC, Johan Engelen wrote:On Thursday, 18 August 2016 at 11:43:03 UTC, Lodovico Giaretta wrote:Well, LDC 1.1.0 is based on DMD 2.071.1, while I tested the above code on asm.dlang.org with DMD 2.071.0, so maybe on DMD 2.071.1 it works too. On nightly it works for sure. So again nothing wrong here, just a matter of having the most recent compiler version.Which compiler version are you using? On DMD 2.071.0 this does not work.Note: this does work with LDC 1.1.0 even though it is based on DMD 2.071. https://github.com/ldc-developers/ldc/releases/tag/v1.1.0-beta2
Aug 18 2016
On Thursday, 18 August 2016 at 16:41:27 UTC, Lodovico Giaretta wrote:On Thursday, 18 August 2016 at 16:19:41 UTC, Johan Engelen wrote:No, i'm using the newest version of dmd/ldc2 (2.071.1/1.0.0) released.On Thursday, 18 August 2016 at 11:43:03 UTC, Lodovico Giaretta wrote:Well, LDC 1.1.0 is based on DMD 2.071.1, while I tested the above code on asm.dlang.org with DMD 2.071.0, so maybe on DMD 2.071.1 it works too. On nightly it works for sure. So again nothing wrong here, just a matter of having the most recent compiler version.Which compiler version are you using? On DMD 2.071.0 this does not work.Note: this does work with LDC 1.1.0 even though it is based on DMD 2.071. https://github.com/ldc-developers/ldc/releases/tag/v1.1.0-beta2
Aug 18 2016