【linux】学习7

鸟哥 22章内容

 

单个源代码编译运行

设有一个hello.c 可以用下面方式运行 生成可执行文件a.out

[localhost scripts]$ gcc hello.c 
[localhost scripts]$ ll hello.c a.out
[localhost scripts]$ ./a.out
Hello world

也可以 会生成 目标文件hello.o 和可执行文件hello

[localhost scripts]$ gcc -c hello.c
[localhost scripts]$ gcc -o hello hello.o
[localhost scripts]$ ./hello
Hello world

 

多个源代码编译运行

设有thanks.c 和 thanks_2.c 两个源文件

[localhost scripts]$ gcc -c thanks.c thanks_2.c     
[localhost scripts]$ gcc -o thanks thanks.o thanks_2.o
[localhost scripts]$ ./thanks
Hello World
Thank you!

优化参数

-O :生成优化的参数

-Wall: 产生详细的编译信息

[localhost scripts]$ gcc -O -c thanks.c thanks_2.c
[localhost scripts]$ gcc -Wall -c thanks.c thanks_2.c
thanks.c: In function 'main':
thanks.c:5: warning: implicit declaration of function 'thanks'
thanks.c:6: warning: control reaches end of non-void function

加入链接的函数库

gcc sin.c -lm -L/lib -L/usr/lib

-l 加入函数库

m 表示加入的是libm.so 函数库

-L 表示函数库在其后面的路径搜索

 

gcc sin.c -lm -I/usr/include

-I 表示在后面的文件中搜索include文件

                 

Makefile

设有  main.c haha.c sin_value.c cos_value.c 四个源文件

makefile中用变量来简化重复的内容,命令行命令前用<TAB>键  

LIBS = -lm
OBJS = main.o haha.o sin_value.o cos_value.o
main: ${OBJS}
        gcc -o main ${OBJS} ${LIBS}
clean:
        rm -f main ${OBJS}

make main  表示编译执行

make clean 表示清除已有目标文件

make clean main 表示先清除,再执行

    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值