是否可以在一个平台上编译程序并与其他平台链接?目标文件包含什么?我们可以取消链接可执行文件以生成目标文件吗?
最佳答案
没有。一般来说,目标文件格式可能是相同的,例如ELF,但目标文件的内容会因系统而异。
一个目标文件包含如下内容:
Object code that implements the desired functionality
A symbol table that can be used to resolve references
Relocation information to allow the linker to locate the object code in memory
Debugging information
目标代码通常不仅是特定于处理器的,而且是特定于操作系统的,例如,它包含系统调用。
编辑:
Is it possible to compile program on one platform and link with other ?
当然。如果您使用交叉编译器。该编译器专门针对一个平台并生成与目标平台兼容的目标文件(和程序)。因此,您可以使用 X86 Linux 系统,例如,使用适当的交叉编译器为基于 powerpc 或 ARM 的系统制作程序。我做 here .
关于c++ - 目标文件平台独立吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2123480/