Thread overview | ||||||
---|---|---|---|---|---|---|
|
July 31, 2008 Instantiating a class in d file with an extern (c) block causes immediate segfault! | ||||
---|---|---|---|---|
| ||||
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? |
July 31, 2008 Re: Instantiating a class in d file with an extern (c) block causes immediate segfault! | ||||
---|---|---|---|---|
| ||||
Posted in reply to kamatsu | 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?
>
|
July 31, 2008 Re: Instantiating a class in d file with an extern (c) block causes immediate segfault! | ||||
---|---|---|---|---|
| ||||
Posted in reply to kamatsu | 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
|
August 01, 2008 Re: Instantiating a class in d file with an extern (c) block causes immediate segfault! | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gregor Richards | 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
|
Copyright © 1999-2021 by the D Language Foundation