gcc编译器实验---对gcc编译参数的详细说明

[root@localhost gcc]# ls
hello.c
[ root@localhost gcc]#  gcc hello.c -o hello   //“-o”,编译生成可执行文件hello(预处理、编译、汇编、连接一步完成)
[root@localhost gcc]# ls
hello  hello.c
[root@localhost gcc]# ./hello
hello world!!
[root@localhost gcc]#  gcc -E  hello.c -o hello.i //“-E”,只进行预处理,不做其它处理,生成hello.i文件
[root@localhost gcc]# ls
hello  hello.c   hello.i  //可以用cat hello.i查看hello.i文件内容,可以看到头文件#include <stdio.h>经过预处理后, 编译器已将stdio.h内容贴近来
[root@localhost gcc]#  gcc -S  hello.c -o hello.s  //“-S”编译生成汇编代码
[root@localhost gcc]# ls
hello  hello.c  hello.i   hello.s
[root@localhost gcc]# gcc -C  hello.c -o hello.o
gcc: GCC does not support -C or -CC without -E
[root@localhost gcc]#  gcc -c  hello.c -o hello.o  //小“-c”,只是编译不链接,生成目标链接库“hello.o”文件
[root@localhost gcc]# ls
hello  hello.c  hello.i   hello.o  hello.s
[root@localhost gcc]# rm hello -r
rm:是否删除 一般文件 “hello”? y
[root@localhost gcc]# ls
hello.c  hello.i  hello.o  hello.s
[root@localhost gcc]#  gcc hello.o -o hello //将编译好的hello.o链接库文件,生成可执行文件hello
[root@localhost gcc]# ls
hello  hello.c  hello.i  hello.o  hello.s
[root@localhost gcc]# ./hello
hello world!!
[root@localhost gcc]#
 
[root@localhost gcc]#  gcc -g hello.c -o hello1  //“-g”,编译生成带有标准信息的可执行文件hello1, 可以使用GDB调试
[root@localhost gcc]# ls
hello  hello1  hello.c  hello.i  hello.o  hello.s
[root@localhost gcc]# ./hello1 
hello world!!
[root@localhost gcc]# gcc hello.c -o static hello2 
gcc: hello2:没有那个文件或目录
[root@localhost gcc]# gcc hello.c static -o  hello2
gcc: static:没有那个文件或目录
[root@localhost gcc]#  gcc hello.c -static -o  hello2   //“-static”,静态链接库生成的可执行文件hello2
[root@localhost gcc]# ls
hello  hello1  hello2  hello.c  hello.i  hello.o  hello.s
[root@localhost gcc]# ./hello2
hello world!!
[root@localhost gcc]# ll
总计 560
-rwxr-xr-x 1 root root   4729 11-29 18:51 hello
-rwxr-xr-x 1 root root   5881 11-29 20:40 hello1
-rwxr-xr-x 1 root root 518848 11-29 20:43 hello2 //静态链接库的可执行文件hello2比动态连接库的可执行文件hello大得多
-rw-r--r-- 1 root root     74 11-29 08:31 hello.c
-rw-r--r-- 1 root root  18001 11-29 18:47 hello.i
-rw-r--r-- 1 root root    876 11-29 18:50 hello.o
-rw-r--r-- 1 root root    446 11-29 18:49 hello.s
[root@localhost gcc]#  gcc -O2 hello.c -o  hello3   //“-O2”,完成程序的优化工作
[root@localhost gcc]# ls
hello  hello1  hello2  hello3  hello.c  hello.i  hello.o  hello.s
[root@localhost gcc]# ./hello3
hello world!!
[root@localhost gcc]# ll
总计 568
-rwxr-xr-x 1 root root   4729 11-29 18:51 hello
-rwxr-xr-x 1 root root   5881 11-29 20:40 hello1
-rwxr-xr-x 1 root root 518848 11-29 20:43 hello2
-rwxr-xr-x 1 root root   4745 11-29 20:45 hello3   //优化的可执行文件hello3,文件大小比较
-rw-r--r-- 1 root root     74 11-29 08:31 hello.c
-rw-r--r-- 1 root root  18001 11-29 18:47 hello.i
-rw-r--r-- 1 root root    876 11-29 18:50 hello.o
-rw-r--r-- 1 root root    446 11-29 18:49 hello.s
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值