目标文件包含什么?

2023-10-17C/C++开发问题
0

本文介绍了目标文件包含什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

在 C 或 C++ 编译的各个阶段,我知道生成了一个目标文件(即 any_name.o 文件).这个 .o 文件包含什么?我无法打开它,因为它是一个二进制文件.

During the various stages of compilation in C or C++, I know that an object file gets generated (i.e., any_name.o file). What does this .o file contain? I can't open it since it's a binary file.

有人可以帮我吗?目标文件的内容是否主要取决于我们在 Unix 上使用的编译器?

Could anybody please help me? Are the contents of the object file mainly dependent on the compiler which we use on Unix?

推荐答案

对象文件可以包含一堆东西:基本上是下面的部分或全部列表:

Object files can contain a bunch of stuff: Basically it's some or all of the list below:

  • 符号名称
  • 编译代码
  • 常量数据,例如.字符串
  • 导入 - 编译后的代码引用了哪些符号(由链接器修复)
  • 导出 - 目标文件可用于其他目标文件的符号.

链接器通过匹配所有导入和导出,并修改编译后的代码以便调用正确的函数,将一堆目标文件转换为可执行文件.

The linker turns a bunch of object files into an executable, by matching up all the imports and exports, and modifying the compiled code so the correct functions get called.

这篇关于目标文件包含什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6