C语言001–hello world编译详解



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  //&#x9884;&#x5904;&#x7406;&#xFF0C;&#x751F;&#x6210; .i &#x6587;&#x4EF6;
book@100ask:~/linux/c01$ file hello.i
hello.i: C source, ASCII text
book@100ask:~/linux/c01$ gcc -S hello.i -o hello.s   //&#x7F16;&#x8BD1;&#xFF0C;&#x751F;&#x6210; .s &#x6587;&#x4EF6;
book@100ask:~/linux/c01$ file hello.s
hello.s: assembler source, ASCII text
book@100ask:~/linux/c01$ gcc -c hello.s -o hello.o    //&#x6C47;&#x7F16;&#xFF0C;&#x751F;&#x6210; .o &#x6587;&#x4EF6;&#xFF0C;-c&#x9009;&#x9879;&#x53EA;&#x7F16;&#x8BD1;&#x4E0D;&#x94FE;&#x63A5;
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   //&#x94FE;&#x63A5;&#xFF0C;&#x751F;&#x6210;&#x53EF;&#x6267;&#x884C;&#x6587;&#x4EF6;
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      //&#x6267;&#x884C;&#x7A0B;&#x5E8F;
hello world!

Original: https://www.cnblogs.com/emolife/p/16688597.html
Author: imagelife
Title: C语言001–hello world编译详解

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/577806/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球