How to compile D application without the D runtime

2019-03-20 07:25发布

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!

标签: d dmd druntime
2条回答
欢心
2楼-- · 2019-03-20 08:05
ldc -nodefaultlib -noruntime

I've had success with that. But you'll still want to add:

extern(C) __gshared void* _Dmodule_ref;
extern(C) int main() {}

Note that while the runtime is optional, it is required for a lot of the features. You'll be missing array slicing, (dynamic arrays?), GC, and plenty of others. If you accidentally use one of those features, you'll get plenty of warnings about how it can't find some obscure symbol name.

查看更多
仙女界的扛把子
3楼-- · 2019-03-20 08:18
module main;
extern(C) __gshared void* _Dmodule_ref;
extern(C) int main() {
    int a = 2 + 3;
    return 0;
}
查看更多
登录 后发表回答