德尔福dcu到obj(Delphi dcu to obj)

编程入门 行业动态 更新时间:2024-10-25 08:19:21
德尔福dcu到obj(Delphi dcu to obj)

有没有办法将Delphi .dcu文件转换为.obj文件,以便可以使用像GCC这样的编译器进行链接? 我已经使用Delphi几年了,但是如果可能的话,我想再次使用它。

Is there a way to convert a Delphi .dcu file to an .obj file so that it can be linked using a compiler like GCC? I've not used Delphi for a couple of years but would like to use if for a project again if this is possible.

最满意答案

Delphi可以输出.obj文件,但它们是英特尔OMF的32位版本。 另一方面,GCC可与ELF(Linux,大多数Unix),COFF(Windows)或Mach-O(Mac)协同工作。

但仅此而已,这还不够。 在不使用运行时库的情况下编写很多代码很困难,运行时库的实现将依赖于编译器和链接器体系结构的低级细节,例如正确的初始化顺序。

而且,除了目标文件格式之外,还有更多的兼容性。 Linux上的代码尤其需要与位置无关,这意味着它不能使用绝对值来引用全局符号,而是必须从寄存器或相对于指令指针索引其全局数据,以便代码可以在不重写引用的情况下重定位到内存中。

DCU文件是Delphi符号表和为每个proc生成的代码的序列化,因此高度依赖于编译器的实现细节,编译器的实现细节从一个版本变为另一个版本。

所有这一切都意味着,除非将自己限制在非管理数据类型(无字符串,无接口)的绝对最小值之外,否则您不太可能将更多的Delphi(dcc32)代码链接到GNU环境中,并且程序代码(没有类,没有初始化部分,没有需要初始化的数据等)

Delphi can output .obj files, but they are in a 32-bit variant of Intel OMF. GCC, on the other hand, works with ELF (Linux, most Unixes), COFF (on Windows) or Mach-O (Mac).

But that alone is not enough. It's hard to write much code without using the runtime library, and the implementation of the runtime library will be dependent on low-level details of the compiler and linker architecture, for things like correct order of initialization.

Moreover, there's more to compatibility than just the object file format; code on Linux, in particular, needs to be position-independent, which means it can't use absolute values to reference global symbols, but rather must index all its global data from a register or relative to the instruction pointer, so that the code can be relocated in memory without rewriting references.

DCU files are a serialization of the Delphi symbol tables and code generated for each proc, and are thus highly dependent on the implementation details of the compiler, which changes from one version to the next.

All this is to say that it's unlikely that you'd be able to get much Delphi (dcc32) code linking into a GNU environment, unless you restricted yourself to the absolute minimum of non-managed data types (no strings, no interfaces) and procedural code (no classes, no initialization section, no data that needs initialization, etc.)

更多推荐

本文发布于:2023-08-01 15:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1361426.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:德尔福   dcu   Delphi   obj

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!