www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Interfacing C++ to D

reply ANtlord <antlord92 gmail.com> writes:
Hello!

Can somebody give a relevant example shows how to use C++ classes 
in D? I've used the exmaple from 
https://dlang.org/spec/cpp_interface.html but I get a 
segmentation fault as result of D application. My application 
shows "Program exited with code -11"

Thanks.
Apr 01 2017
parent reply FreeSlave <freeslave93 gmail.com> writes:
On Saturday, 1 April 2017 at 07:37:25 UTC, ANtlord wrote:
 Hello!

 Can somebody give a relevant example shows how to use C++ 
 classes in D? I've used the exmaple from 
 https://dlang.org/spec/cpp_interface.html but I get a 
 segmentation fault as result of D application. My application 
 shows "Program exited with code -11"

 Thanks.
This page has many examples. Which exactly do you try to run and how do you build it? Which compilers, OS?
Apr 01 2017
parent reply ANtlord <antlord92 gmail.com> writes:
On Saturday, 1 April 2017 at 16:39:28 UTC, FreeSlave wrote:
 This page has many examples. Which exactly do you try to run 
 and how do you build it? Which compilers, OS?
My bad. I've tested example under caption Using C++ Classes From D. I used several combinations of compilers, and no one works for me. OS: ArchLinux D compilers: DMD 2.073.2, LDC 1.1.0 C++ compiler: gcc 6.3.1, clang 3.9 Also I've created reposotory contains test project. Anyone can take a look on that for clearance. https://github.com/ANtlord/cpp_to_d_test
Apr 02 2017
next sibling parent ANtlord <antlord92 gmail.com> writes:
On Sunday, 2 April 2017 at 09:58:19 UTC, ANtlord wrote:
 On Saturday, 1 April 2017 at 16:39:28 UTC, FreeSlave wrote:
 This page has many examples. Which exactly do you try to run 
 and how do you build it? Which compilers, OS?
My bad. I've tested example under caption Using C++ Classes From D. I used several combinations of compilers, and no one works for me. OS: ArchLinux D compilers: DMD 2.073.2, LDC 1.1.0 C++ compiler: gcc 6.3.1, clang 3.9 Also I've created reposotory contains test project. Anyone can take a look on that for clearance. https://github.com/ANtlord/cpp_to_d_test
I've tested also on Ubuntu 16.04 and DMD v2.073.1 with gcc 5.4.0
Apr 02 2017
prev sibling parent reply FreeSlave <freeslave93 gmail.com> writes:
On Sunday, 2 April 2017 at 09:58:19 UTC, ANtlord wrote:
 On Saturday, 1 April 2017 at 16:39:28 UTC, FreeSlave wrote:
 This page has many examples. Which exactly do you try to run 
 and how do you build it? Which compilers, OS?
My bad. I've tested example under caption Using C++ Classes From D. I used several combinations of compilers, and no one works for me. OS: ArchLinux D compilers: DMD 2.073.2, LDC 1.1.0 C++ compiler: gcc 6.3.1, clang 3.9 Also I've created reposotory contains test project. Anyone can take a look on that for clearance. https://github.com/ANtlord/cpp_to_d_test
Now I see. 'Using C++ Classes From D' crashes for me too. It also returns the wrong value from 'field' method. Should be 5, but it returns 0. Probably regression.
Apr 02 2017
parent reply FreeSlave <freeslave93 gmail.com> writes:
On Sunday, 2 April 2017 at 16:02:06 UTC, FreeSlave wrote:
 On Sunday, 2 April 2017 at 09:58:19 UTC, ANtlord wrote:
 On Saturday, 1 April 2017 at 16:39:28 UTC, FreeSlave wrote:
 This page has many examples. Which exactly do you try to run 
 and how do you build it? Which compilers, OS?
My bad. I've tested example under caption Using C++ Classes From D. I used several combinations of compilers, and no one works for me. OS: ArchLinux D compilers: DMD 2.073.2, LDC 1.1.0 C++ compiler: gcc 6.3.1, clang 3.9 Also I've created reposotory contains test project. Anyone can take a look on that for clearance. https://github.com/ANtlord/cpp_to_d_test
Now I see. 'Using C++ Classes From D' crashes for me too. It also returns the wrong value from 'field' method. Should be 5, but it returns 0. Probably regression.
Funny thing: If I replace interface with abstract class, it works as it should.
Apr 02 2017
next sibling parent FreeSlave <freeslave93 gmail.com> writes:
On Sunday, 2 April 2017 at 16:03:51 UTC, FreeSlave wrote:
 On Sunday, 2 April 2017 at 16:02:06 UTC, FreeSlave wrote:
 On Sunday, 2 April 2017 at 09:58:19 UTC, ANtlord wrote:
 [...]
Now I see. 'Using C++ Classes From D' crashes for me too. It also returns the wrong value from 'field' method. Should be 5, but it returns 0. Probably regression.
Funny thing: If I replace interface with abstract class, it works as it should.
Reported issue: https://issues.dlang.org/show_bug.cgi?id=17293
Apr 02 2017
prev sibling parent ANtlord <antlord92 gmail.com> writes:
On Sunday, 2 April 2017 at 16:03:51 UTC, FreeSlave wrote:
 Funny thing: If I replace interface with abstract class, it 
 works as it should.
Also I noticed that removing inheritance in library and in application makes unexpected results. When I try to output field `field` I get incorrect random value. It looks like that the field is got by wrong address. For clearance I created branch `removed-inheritance`.
Apr 03 2017