www.digitalmars.com         C & C++   DMDScript  

D.gnu - Instantiating a class in d file with an extern (c) block causes immediate segfault!

reply kamatsu <whiteslug gmail.com> writes:
Content-Type: text/plain

On my system, when I do:

gdc *.c *.d
./a.out

I get:

segmentation fault

I can instantiate classes fine with normal D, but as soon as the extern(c)
stuff creeps in bang - no classes for me!

Can you please explain what's wrong? And how I can fix it?
Jul 31 2008
next sibling parent John Grindstaff <perfectcell14 yahoo.com> writes:
Is this version of gdc you are using compiled against GCC 4.2.* or 
4.1.*? If you are trying to use nested functions, it is probably best to 
use 4.1 because I have had random crashes with nested functions in 4.2.*

kamatsu wrote:
 On my system, when I do:
 
 gdc *.c *.d
 ./a.out
 
 I get:
 
 segmentation fault
 
 I can instantiate classes fine with normal D, but as soon as the extern(c)
stuff creeps in bang - no classes for me!
 
 Can you please explain what's wrong? And how I can fix it?
 

Jul 31 2008
prev sibling parent reply Gregor Richards <Richards codu.org> writes:
kamatsu wrote:
 On my system, when I do:
 
 gdc *.c *.d
 ./a.out
 
 I get:
 
 segmentation fault
 
 I can instantiate classes fine with normal D, but as soon as the extern(c)
stuff creeps in bang - no classes for me!
 
 Can you please explain what's wrong? And how I can fix it?
 

You're using a C main and haven't initialized the D environment. Initializing D from C is quite difficult, I would recommend using a D main (such that D is initialized automatically) and using it to call the primary C function. - Gregor Richards
Jul 31 2008
parent FreekSh0w86 <perfectcell14 yahoo.com> writes:
Oh I had no idea this was an attempt to invoke D runtime from a C 
program. If you manage to do that on a non-Windows platform 
successfully, that would be a super-human feat. The only way I've 
managed to even come close to doing something like that is build all my 
source objects separately into *.o files and link them together with GDC 
_and_ invoke the D runtime by calling rt_init or whatever. But that is 
for Tango, Phobos is probably different.


Gregor Richards wrote:
 kamatsu wrote:
 On my system, when I do:

 gdc *.c *.d
 ./a.out

 I get:

 segmentation fault

 I can instantiate classes fine with normal D, but as soon as the 
 extern(c) stuff creeps in bang - no classes for me!

 Can you please explain what's wrong? And how I can fix it?

You're using a C main and haven't initialized the D environment. Initializing D from C is quite difficult, I would recommend using a D main (such that D is initialized automatically) and using it to call the primary C function. - Gregor Richards

Jul 31 2008