我可以将由一个编译产生的对象文件链接到另一个编译的对象文件吗? [英] Can I link object files made by one compile to those made by another one?

查看:223
本文介绍了我可以将由一个编译产生的对象文件链接到另一个编译的对象文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更具体地说,假设两个编译器都在同一平台(OS +指令集)上。但是,其中一个目标文件是由编译器依赖的代码。另一方面 - 代码是面向对象的,并且尊重封装。



我需要这种框架。目标平台是任何系统,其中是GCC和Java虚拟机。实际上,框架将在每个平台上编译。

解决方案

你应该能够链接他们,只要他们使用相同的目标文件格式和目标相同的机器指令集。例如,假设您有两个C编译器,每个编译器都有自己的专有语言扩展。你编译两个不同的文件,一个使用编译器A,另一个使用编译器B.每个源文件使用它各自的编译器的语言扩展。只要两个编译器都设置为目标相同的平台和架构,例如在Linux上的i386指令集,那么您应该能够将文件链接到一个可执行文件。



在维基上查看此对象文件格式列表。



这可能也是您感兴趣的:



用于浏览对象文件的UNIX工具



编辑



根据本文, C ++标准库ABI ,有一个工业标准的C ++ ABI,你应该能够链接符合这个标准的任何编译器的对象文件。您可以在这里查看该标准:



Itanium C ++ ABI


本文档由
联合开发的非正式行业联盟
组成(按字母顺序排列订单)
CodeSourcery,Compaq,EDG,HP,IBM,
Intel,Red Hat和SGI ...



在本文档中,为C ++
程序指定
应用程序二进制接口,即用户C ++代码和
之间的对象代码
接口,实现提供的系统和
库。这包括用于C ++数据对象的内存
布局,包括
预定义和用户定义数据
类型,以及内部编译器
生成的对象,如虚拟
表。它还包括函数
调用接口,异常处理
接口,全局命名和各种
对象代码约定。


因此,只要你使用相同的指令集,目标文件格式并使用标准C ++ ABI(现在是gcc / g ++中的默认值),那么你应该确定,假设标准C ++ ABI是实际上是标准的,并且由在Linux上运行的大多数现代C ++编译器(它似乎是您定位的平台)正确实现。



编辑2



您应该看一下这篇文章:



GCC与MS C ++编译器,用于维护API向后二进制兼容性



似乎微软没有遵循任何一致的标准(Itanium或其他)关于他们的C + + ABI,所以如果你编译gcc的Windows,它可能会是一个问题。 / p>

您可能还想查看这两篇文章:



C ++的政策/二进制兼容性问题



二进制兼容性的一些想法



到支持Itanium ABI的编译器,但这取决于您的目标受众。


To be more specific, lets assume that both compilers are on the same platform (OS + instruction set). However, one of the object files was made from a compiler-dependent code. On the other hand - the code is object oriented and respects encapsulation.

I need this for a kind of a framework I am making. Target platform is any system where is GCC and Java Virtual Machine. Indeed the framework will be compiled on each platform. The compiler which use the framework user is up to him.

解决方案

You should be able to link them as long as they use the same object file format and target the same machine instruction set. For example, say you have two C compilers each with it's own proprietary language extensions. You compile two different files, one with compiler A the other with compiler B. Each source file uses language extensions of it's respective compiler. As long as both compilers are set to target the same platform and architecture, for example i386 instruction set on Linux, then you should be able to link the files into one executable.

See this list of object file formats on wiki.

This might also be of interest to you:

UNIX tools for exploring object files

EDIT

According to this article, "C++ Standard Library ABI", there is an industry standard C++ ABI and you should be able to link objects files of any compiler which conforms to this standard. You can see that standard here:

Itanium C++ ABI

This document was developed jointly by an informal industry coalition consisting of (in alphabetical order) CodeSourcery, Compaq, EDG, HP, IBM, Intel, Red Hat, and SGI...

In this document, we specify the Application Binary Interface for C++ programs, that is, the object code interfaces between user C++ code and the implementation-provided system and libraries. This includes the memory layout for C++ data objects, including both predefined and user-defined data types, as well as internal compiler generated objects such as virtual tables. It also includes function calling interfaces, exception handling interfaces, global naming, and various object code conventions.

So as long as you target the same instruction set, object file format and use the standard C++ ABI ( which is now the default in gcc / g++ ) you should be ok, assuming of course that the standard C++ ABI is actually standard and properly implemented by most modern C++ compilers that run on Linux ( which seems to be the platform you're targeting ).

EDIT 2

You should take a look at this SO post:

GCC vs MS C++ compiler for maintaining API backwards binary compatibility

It seems like Microsoft doesn't follow any consistent standard ( Itanium or otherwise ) regarding their C++ ABI, so if you compile with gcc for Windows it likely is going to be a problem.

You probably also want to look at these two articles:

Policies/Binary Compatibility Issues With C++

Some thoughts on binary compatibility

You could restrict your users to compilers which support the Itanium ABI, but that depends on your target audience.

这篇关于我可以将由一个编译产生的对象文件链接到另一个编译的对象文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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