如何在没有D运行时的情况下编译D应用程序? [英] How to compile D application without the D runtime?

查看:93
本文介绍了如何在没有D运行时的情况下编译D应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图永远解决这个问题,这开始惹恼我.我了解D运行时库.它是什么,它做什么.我也了解,没有它,您也可以编译D应用程序.就像XoMB所做的一样.好吧,XoMB定义了自己的运行时,但是在某些情况下,您不需要编写自己的运行时.我了解我正在使用的DigitalMars D编译器(dmd)在运行时在幕后做了很多事情,例如根据程序所需的内容发出对某些事情的引用.而且,每个程序都需要处理.因此,您必须自己定义这些.我决定尝试一下,尝试自己弄清楚,然后走了很远.我的意思是让链接器吐出越来越少的错误.为了进行测试,我只想编译一个完整的准系统 应用程序,仅需运行时即可运行.或尽可能少的运行时.这是我唯一的源文件.

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;
}

我使用以下命令编译:dmd -c main.d -defaultlib =

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

然后链接:link main.obj

Then link with: link main.obj

这是我得到的错误:OPTLINK:警告23:无堆栈& OPTLINK:警告134:没有起始地址

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

您可以看到我尝试将main拖到_main,以摆脱没有起始地址的错误,但是, 无论如何,没有帮助.我该怎么办才能解决这最后两个错误?如果我能使其正常运行,我想我可以查找实现更多功能所需的实现.但是,如果有人愿意帮我解决这个问题,那就太感激了!

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!

推荐答案

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

这篇关于如何在没有D运行时的情况下编译D应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆