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
How do I create ELF executables?
提问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.out
files are different from ELF executables.
我在某处读到a.out
文件与 ELF 可执行文件不同。
How do I instruct gcc
to create ELF executable?
如何指示gcc
创建 ELF 可执行文件?
采纳答案by larsks
In fact, gcc
uses the name a.out
for historical reasons. You're actuall getting an ELF
executable. You can verify this with the file
command, 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 -o
switch to change the output filename:
如果您不想看到 name a.out
,请使用-o
开关更改输出文件名:
g++ -o hello hello.cpp
Note also that while gcc
often 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 文件。