www.digitalmars.com         C & C++   DMDScript  

D.gnu - compiling d code without phobos ?

reply Wiz <thewizhard msn.com> writes:
I'm currently working on a little OS, and my goal is to use the D 
language as the main one.
I had no problem to build a running very very primitive version, but 
when I tried to define (not even using it), I have seen some troubles : 
gdc tells me there is a few reference that are undefined.
Right, theses references are the phobos ones : I have no need of since 
phobos can't work on my system yet (memory allocs and lot of things are 
going to be rebuild by myself later).
I then tried to make my own object.d file, I put it into my kernel 
folder and added it to the makefile, I still have some problems...
When compiling my version of object.d containing just a class definition 
'object', gdc seg faults. It seems to me that gdc imports 
mingw/include/d/3.4.5/object.d before compiling mine, and don't know 
what to do in the case of these two.
I also before got a error telling me the class was already defined (but 
don't remember how, from what I know there is no notable difference 
between the yesterdays context, and todays one), that's wy I ask if 
anybody knows any way of not using the phobos object.d, just my own ?
Tried the -nostdlib of gcc, without any positive results.

ps: Using windows version of gdc (GCC) 3.4.5 (mingw special) (gdc 0.19, 
using dmd 0.162)
Dec 16 2006
next sibling parent Johan Granberg <lijat.meREM OVE.gmail.com> writes:
Wiz wrote:

 I'm currently working on a little OS, and my goal is to use the D
 language as the main one.
 I had no problem to build a running very very primitive version, but
 when I tried to define (not even using it), I have seen some troubles :
 gdc tells me there is a few reference that are undefined.
 Right, theses references are the phobos ones : I have no need of since
 phobos can't work on my system yet (memory allocs and lot of things are
 going to be rebuild by myself later).
 I then tried to make my own object.d file, I put it into my kernel
 folder and added it to the makefile, I still have some problems...
 When compiling my version of object.d containing just a class definition
 'object', gdc seg faults. It seems to me that gdc imports
 mingw/include/d/3.4.5/object.d before compiling mine, and don't know
 what to do in the case of these two.
 I also before got a error telling me the class was already defined (but
 don't remember how, from what I know there is no notable difference
 between the yesterdays context, and todays one), that's wy I ask if
 anybody knows any way of not using the phobos object.d, just my own ?
 Tried the -nostdlib of gcc, without any positive results.
 
 ps: Using windows version of gdc (GCC) 3.4.5 (mingw special) (gdc 0.19,
 using dmd 0.162)
Have you looked at ares at dsource.org ? It's an alternative to phobos and I think it is more modulare.
Dec 16 2006
prev sibling next sibling parent Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
Wiz wrote:
 I'm currently working on a little OS, and my goal is to use the D 
 language as the main one.
I'm working on a similar project, on and off.
 I had no problem to build a running very very primitive version, but 
 when I tried to define (not even using it), I have seen some troubles : 
 gdc tells me there is a few reference that are undefined.
 Right, theses references are the phobos ones : I have no need of since 
 phobos can't work on my system yet (memory allocs and lot of things are 
 going to be rebuild by myself later).
 I then tried to make my own object.d file, I put it into my kernel 
 folder and added it to the makefile, I still have some problems...
From what I remember, object.d doesn't need much work to be included in a kernel. It doesn't allocate any memory anywhere that I can tell. In fact, I just did a quick diff and the main differences between my version and the one with DMD were substituting some C functions for self-written ones, as well as a local version of some std.string functions. The only printf() uses write strings without further formatting, so you don't even need to implement it using varargs yet. The best way to work is probably to remove all imports, rewrite/copy/remove use of the functions the compiler complains about, then try to link. For every missing symbol the linker complains about, try to find it in the phobos sources (I use grep) and understand what it does. Then either reimplement it, copy it to your source tree, or edit object.d so it isn't used anymore. For instance, you can either implement _d_assert (called when an assertion without message fails) or comment out all such assertions. Also, don't forget to use phobos/internal/object.d as a basis instead of phobos/object.d.
 When compiling my version of object.d containing just a class definition 
 'object', gdc seg faults. It seems to me that gdc imports 
 mingw/include/d/3.4.5/object.d before compiling mine, and don't know 
 what to do in the case of these two.
 I also before got a error telling me the class was already defined (but 
 don't remember how, from what I know there is no notable difference 
 between the yesterdays context, and todays one), that's wy I ask if 
 anybody knows any way of not using the phobos object.d, just my own ?
 Tried the -nostdlib of gcc, without any positive results.
Make sure you -I the directory containing your version of object.d. Also, I invoke ld directly to link to make sure the standard library isn't linked, just my own code.
 ps: Using windows version of gdc (GCC) 3.4.5 (mingw special) (gdc 0.19, 
 using dmd 0.162)
I use DMD for Linux, so there may of course be some differences between our setups. A general tip: Assertion support is one of the first things you want to implement after basic text output is implemented. It's invaluable. Make sure it relies on as little other code as possible though. If your output code has any chance of asserting, implement a simplified copy without assertions specifically for use by error reporting code to prevent infinite loops (yes, I've been bitten by this :( ). My code at first just copied a text message to the screen and halted the system. Later, I extended it to halt only the current thread, provide register dumps and stack traces (with demangled function names), as well as sending all output to a serial port for debugging convenience (it's easy). But first you need to get the basics working, the rest can come later.
Dec 16 2006
prev sibling parent reply "John Reimer" <terminal.node gmail.com> writes:
On Sat, 16 Dec 2006 11:49:05 -0800, Wiz <thewizhard msn.com> wrote:

 I'm currently working on a little OS, and my goal is to use the D  
 language as the main one.
 I had no problem to build a running very very primitive version, but  
 when I tried to define (not even using it), I have seen some troubles :  
 gdc tells me there is a few reference that are undefined.
 Right, theses references are the phobos ones : I have no need of since  
 phobos can't work on my system yet (memory allocs and lot of things are  
 going to be rebuild by myself later).
 I then tried to make my own object.d file, I put it into my kernel  
 folder and added it to the makefile, I still have some problems...
 When compiling my version of object.d containing just a class definition  
 'object', gdc seg faults. It seems to me that gdc imports  
 mingw/include/d/3.4.5/object.d before compiling mine, and don't know  
 what to do in the case of these two.
 I also before got a error telling me the class was already defined (but  
 don't remember how, from what I know there is no notable difference  
 between the yesterdays context, and todays one), that's wy I ask if  
 anybody knows any way of not using the phobos object.d, just my own ?
 Tried the -nostdlib of gcc, without any positive results.

 ps: Using windows version of gdc (GCC) 3.4.5 (mingw special) (gdc 0.19,  
 using dmd 0.162)
I think you need to replace mingw/include/d/3.4.5/object.d with your version. So backup the one there, replace it with yours, and see what happens. GDC has a "weird" directory structure for the intrinsic imports. I'm not sure if that's the fault of the D implementation or the phobos library mechanics hard-wired into D :(. I actually wish the structure were dirt simple for those dmd/gdc users who want to create there own kernels. Right now, it seems to require a certain amount of hackery to get around the setup. At the very least, we'll eventually need a tutorial for how to roll-your-own phobos-replacement and attach it to d. Ares is a good example of a start, but I believe it is dmd only, at this point. -JJR
Dec 17 2006
parent Wiz <thewizhard msn.com> writes:
As you said, I replaced the real phobos object.d with an other version 
by renaming mingw/include/d/ to mingw/include/d2/ and just put a 
object.d file containing :
/class Object
{

}
/
so I'm pretty sure gdc will not use the old version, but a gdc -c 
object.d -o object.o does the exactly same thing :
/object.d:0: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://www.mingw.org/bugs.shtml> for instructions./

Do I must submit a report to that url ? Not even a gdb can helps.


Wiz


John Reimer a écrit :
 I think you need to replace mingw/include/d/3.4.5/object.d with your 
 version.  So backup the one there, replace it with yours, and see what 
 happens.

 GDC has a "weird" directory structure for the intrinsic imports.  I'm 
 not sure if that's the fault of the D implementation or the phobos 
 library mechanics hard-wired into D :(. I actually wish the structure 
 were dirt simple for those dmd/gdc users who want to create there own 
 kernels. Right now, it seems to require a certain amount of hackery to 
 get around the setup.

 At the very least, we'll eventually need a tutorial for how to 
 roll-your-own phobos-replacement and attach it to d.  Ares is a good 
 example of a start, but I believe it is dmd only, at this point.

 -JJR
Dec 19 2006