How to compile D application without the D runtime?

早过忘川 提交于 2019-12-20 23:22:18

问题


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!


回答1:


module main;
extern(C) __gshared void* _Dmodule_ref;
extern(C) int main() {
    int a = 2 + 3;
    return 0;
}



回答2:


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.



来源:https://stackoverflow.com/questions/13573289/how-to-compile-d-application-without-the-d-runtime

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!