本文介绍了我怎样才能在Linux上生成ELF文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上研究了很多关于ELF文件的知识,但是我找不到我想要的东西。我正在Linux OS上编写C和C ++代码,并使用gcc和Kate程序。完成我的代码后,我想生成ELF可执行文件。我只能生成a.out文件,我不需要它。我如何获得ELF文件? ELF文件是由什么发生的?或者是否有可能用这个程序生成这个文件?

解决方案

编译器(即 code>或 g ++ )将调用产生ELF可执行文件的链接器( ld )。

实际上,您将使用构建器程序(如 make )来驱动 gcc 命令。请参阅。



<$的默认输出文件c $ c> gcc 仍然被命名为 a.out (出于历史原因),但是是ELF文件。你真的想要 gcc 来输出一个更加奇特的名字的可执行文件。



简单的例子,你的代码单个文件 hello-world.c 程序。你可以用例如

  gcc -Wall -g hello-world.c -o hello-world-bin 


和产生的 hello-world-bin 是可执行文件。请检查

  file hello-world-bin 

然后用

  ./hello-world-bin运行它。 

稍后,学习如何使用 gdb 调试器。



另请参阅和回答。


I researched a lot about ELF file on web but I couldn't find what exactly I want. I am writing C and C++ code on Linux OS and I am using gcc and Kate program. After finishing my code, I would like to generate ELF executable file. I just can generate "a.out" file and I don't need it. How can I get ELF file ? ELF file occurs as a result of what ? or Is it possible to generate this file with this program ?

解决方案

The compiler (i.e. gcc or g++) will invoke the linker (ld) which produces an ELF executable.

In practice, you will use a builder program (like make) to drive gcc commands. See this answer.

The default output file for gcc is still named a.out (for historical reasons) but is an ELF file. And you really want to ask gcc to output an executable with a more fancy name.

Simple example, you code a single-file hello-world.c program. You can compile it with e.g.

 gcc -Wall -g hello-world.c -o hello-world-bin

and the produced hello-world-bin is an ELF executable. Check with

 file hello-world-bin

then run it with

 ./hello-world-bin your arguments to it

Later, learn how to use the gdb debugger on it.

See also this and that answers.

这篇关于我怎样才能在Linux上生成ELF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 19:04