rpm构建
linux distribution linux发行版
tarball
为了减少网络资源浪费,将源码进行压缩,tar --> gzip == tar.gz
gcc
gcc hello.c 默认生成a.out ./a.out执行
gcc -c hello.c 生成hello.o ./hello.o
gcc -O hello.c -c 自动生成hello.o并进行优化
gcc -o hello hello.c 生成hello.o hello ./hello
gcc -o thank thank.o thanks2.o ==> ./thank 这就是-o的作用,多个.o文件的时候可以链接
gcc -Wall 打印更详细的编译过程
调用外部链接
gcc sin.c -lm -L/lib -L/usr/lib ==> ./a.out
-lm == sin函数在libm.so里 -L表示去这个路径下去搜索 lm指libm.so或libm.a
gcc sin.c -lm -I/usr/include -I为头文件#include 搜索的路径
-Wall -O 是非必要的flag,程序是c,所以又叫CFLAGS
make
vim makefile
main: main.o hh.o sin.o cos.o
gcc -c main.c hh.c sin.c cos.c
注意是Tab
make
目标(target) :目标文件1 目标文件2
$@: 代表目前的目标,对于上述 gcc -o $@ main.c ... 就代表目标main
./configure makeclean make makeinstall
./configure
建立MakeFile过程
cmake也是自动生成makefile,但是需要自己写cmakelist
./configure
- --prefix=/path 指定软件装到那里去,默认usr/local
过程中会生成makefile
函数库
- 静态库 Static libxxx.a
当函数库升级后,需要重新编译 - 动态库 Dynamic libxxx.so
当函数库升级后,不需要重新编译
linux distribution 目前倾向于使用动态函数库,因为函数库的升级影响比较小
函数库一般放在 /usr/lib
kernel提供的函数库放在/lib/modules/
注意:不同版本内核提供的函数库区别还是很大的
增加函数库的读取性能
事先读取动态库加载到内存当中,需要ldconfig 和/etc/ld.so.conf
- 在/etc/ld.so.conf中写入要读取的动态库的目录
- 利用ldconfig将其读入高速缓存中
- 同时将数据记录一份在/etc/ld.so.cache中
查看软件含有的动态函数库
ldd /usr/bin/passwd