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

FreekSh0w86 perfectcell14 at yahoo.com
Thu Jul 31 18:56:52 PDT 2008


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


More information about the D.gnu mailing list