1.编写hello.c程序,并编译运行
book@100ask:~/linux/c01$ cat hello.c -n
1 #include <stdio.h>
2
3 int main(void)
4 {
5 printf("hello world!\n");
6 return 0;
7 }
book@100ask:~/linux/c01$ gcc hello.c -o hello
book@100ask:~/linux/c01$ ./hello
hello world!
</stdio.h>
2.hello.c编译详解
book@100ask:~/linux/c01$ gcc -E hello.c -o hello.i //预处理,生成 .i 文件
book@100ask:~/linux/c01$ file hello.i
hello.i: C source, ASCII text
book@100ask:~/linux/c01$ gcc -S hello.i -o hello.s //编译,生成 .s 文件
book@100ask:~/linux/c01$ file hello.s
hello.s: assembler source, ASCII text
book@100ask:~/linux/c01$ gcc -c hello.s -o hello.o //汇编,生成 .o 文件,-c选项只编译不链接
book@100ask:~/linux/c01$ file hello.o
hello.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
book@100ask:~/linux/c01$ gcc hello.o -o hello //链接,生成可执行文件
book@100ask:~/linux/c01$ file hello
hello: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=4929e517885a8ac7ff58da69b24c00d8d5622654, not stripped
book@100ask:~/linux/c01$ ./hello //执行程序
hello world!
Original: https://www.cnblogs.com/emolife/p/16688597.html
Author: imagelife
Title: C语言001–hello world编译详解
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/577806/
转载文章受原作者版权保护。转载请注明原作者出处!