Linux 如何创建 ELF 可执行文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8060064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 07:06:16  来源:igfitidea点击:

How do I create ELF executables?

c++linuxgccelf

提问by AppleGrew

Possible Duplicate:
Creating ELF instead of a.out

可能的重复:
创建 ELF 而不是 a.out

When I use the command gcc hello.cpp, I end up with a.out.

当我使用命令时gcc hello.cpp,我以a.out.

I read somewhere that a.outfiles are different from ELF executables.

我在某处读到a.out文件与 ELF 可执行文件不同。

How do I instruct gccto create ELF executable?

如何指示gcc创建 ELF 可执行文件?

采纳答案by larsks

In fact, gccuses the name a.outfor historical reasons. You're actuall getting an ELFexecutable. You can verify this with the filecommand, which will give you output along the lines of:

事实上,gcc使用这个名称是a.out出于历史原因。你实际上得到了一个ELF可执行文件。您可以使用以下file命令验证这一点,该命令将为您提供以下输出:

$ file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, not stripped

回答by Greg Hewgill

If you don't want to see the name a.out, then use the -oswitch to change the output filename:

如果您不想看到 name a.out,请使用-o开关更改输出文件名:

g++ -o hello hello.cpp

Note also that while gccoften works for C++ programs, you should use g++instead.

另请注意,虽然gcc通常适用于 C++ 程序,但您应该使用它g++

回答by Dan

gcc uses the name a.out as the default executable name for historical reasons. If you run "file a.out" you'll see that it's actually an ELF file.

由于历史原因,gcc 使用名称 a.out 作为默认的可执行文件名称。如果您运行“file a.out”,您会看到它实际上是一个 ELF 文件。