Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile D application without the D runtime?

Tags:

d

dmd

druntime

Iv been trying to figure this one out forever, and its starting to annoy me. I understand the D runtime library. What it is, what it does. I also understand that you can compile a D app without it. Like what XoMB does. Well, XoMB defines its own runtime, but there are cases where you dont need to write your own, if you dont need it. I understand that the DigitalMars D compiler (dmd) which is what im using, does alot of things behind the scenes for the runtime, like emiting references to certain things depending on whats needed by your program. And also, things for EVERY program. So you must define these yourself. i decided to experiment, try to figure it out myself and got pretty far. By that i mean getting the linker to spit out less and less errors. For a test i just want to compile a complete bare-bones app, simply to get things working without the runtime. Or as little of runtime as possible. here is what i have my single source file.

module main;

void _main()
{
    int a = 2 + 3;
}

I compile with: dmd -c main.d -defaultlib=

Then link with: link main.obj

And this is the errors i get: OPTLINK : Warning 23: No Stack & OPTLINK: Warning 134: No Start Address

You can see i tried chaingng main to _main to get rid of the no start address error but, anyway, didnt help. What do i need to do to iron out these last two errors? if i can get it working, i think i can look up what i need to implement to get more features working. But if anyone is willing to to help me out with that, it would be much apreciated!

like image 407
kbzombie Avatar asked Nov 26 '12 21:11

kbzombie


1 Answers

module main;
extern(C) __gshared void* _Dmodule_ref;
extern(C) int main() {
    int a = 2 + 3;
    return 0;
}
like image 150
anonymous Avatar answered Oct 07 '22 06:10

anonymous