On Thursday, 31 May 2012 at 08:57:37 UTC, jerro wrote:
On Thursday, 31 May 2012 at 03:04:58 UTC, tim krimm wrote:

I have been looking at the xomb bare bones (XBB) source code.
It looks like they have a bare bones library, no Phobos.
They used ldc for their compiler.

1) Can the same things be done with the DMD version 2 compiler?

2) Will DMD work without the Phobos library?

3) What minimal set of modules do you need for DMD?

GDC has the -nophoboslib flag. So you can write a D file that doesn't use druntime or phobos:

extern(C) int puts(const char *);

extern(C) int main()
{
    puts("Hello world!");
    return 0;
}

and compile it with:

gdc -nophoboslib hello.d

The linker will complain about undefined reference to _Dmodule_ref. So you need to write a c file like with just "void* _Dmodule_ref;" in it and compile it to object file with gcc -c dummy.c. Then you can do

gdc -nophoboslib hello.d dummy.o

And it works.

I just remembered you can do something similar with DMD, too, using -defaultlib. Make a static library containing just _Dmodule_ref:


echo "void* _Dmodule_ref;" | gcc -x c - -c -o dmodule_ref.o
ar cr libdmodule_ref.a dmodule_ref.o

Now put it somewhere where the linker can find it. Now you can compile d programs without druntime like this:

dmd hello.d -defaultlib=dmodule_ref

Reply via email to