c - Linux新手问题: GCC Compiler output

标签 c linux gcc compilation

我是 Linux 的新手。我在笔记本电脑上安装了 Mint,最近一直在玩弄它。

我写了一个简单的 C 程序并保存了文件。 然后在命令行中输入

gcc -c myfile

然后弹出一个名为 a.out 的文件。我天真地(经过多年的 Windows 使用)期望出现一个漂亮的 .exe 文件。我不知道如何处理这个 a.out 文件。

最佳答案

-o命名并跳过-c:

gcc -Wall -o somefile myfile

尽管如此,您应该使用 .c 扩展名来命名您的源文件。

典型的编译方式,例如将两个源文件合并为一个可执行文件:

#Compile (the -c) a file, this produces an object file (file1.o and file2.o)

gcc -Wall -c file1.c
gcc -Wall -c file2.c

#Link the object files, and specify the output name as `myapp` instead of the default `a.out`

gcc -o myapp file1.o file2.o

您可以一步完成:

gcc -Wall -o myapp file1.c file2.c

或者,对于您使用单个源文件的情况:

gcc -Wall -o myapp file.c

-Wall 部分的意思是“启用(几乎)所有警告”——这是您应该从一开始就养成的习惯,它会让您在以后调试奇怪的问题时省去很多麻烦。

a.out 名称是旧 unix 的遗留物,它是一种可执行格式。默认情况下,链接器仍将文件命名为 a.out,尽管它们现在倾向于生成 ELF 而不是 a.out 格式的可执行文件。

关于c - Linux新手问题: GCC Compiler output,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5928006/

相关文章:

C: 为什么 C 或 C++ 中不允许 int[] 数组

c - 为什么crc32值需要-lz

c - 在有或没有 UNICODE 支持的情况下,如何在我的程序中使用 _stprintf?

linux - 写入完成后意外标记 `done' 附近出现语法错误

c - C 中字符串的位置反转

Linux BlueZ 4.101 允许 GATT 连接但不在 Ubuntu 上公开 GATT 服务

c - 使用 pthreads 我只得到大值的 "Segmentation fault (core dumped)"

c - 为什么编译器不给出冲突错误?

c++ - 使用 LSB C++ 编译器构建 Boost

c++ - GCC 优化 : how can less operations be slower?