step2:
#cd ./jpeg-6b
#./configure --prefix=/home/jpeg_arm --exec-prefix=/home/jpeg_arm --enable-shared --enable-static
下面分别介绍这几个参数的作用:
--prefix=/home/jpeg_arm/include : 执行make install 后,会将与体系无关的文件拷贝到此目录下,具体如下:
/home/jpeg_arm_include.....................................
|
+---include........................................
|
---jconfig.h
|
---jerror.h
|
---jmorecfg.h
|
---jpeglib.h
+---man............................................
|
+---man1.......................................
|
---cjeg.1
|
---djpeg.1
|
---jpegtran.1
|
---rdjpgcom.1
|
---wrjpgcom.1
--exec-prefix=/home/jpeg_arm/lib : 执行make install 后,会将与体系无关的文件拷贝到此目录下,即将一些可执行程序、动态链接库和静态链接库拷贝到此目录的相应目录下,具体如下:
/home/jpeg_arm_lib........................................
|
+---bin............................................
|
---cjeg
|
---djpeg
|
---jpegtran
|
---rdjpgcom
|
---wrjpgcom
+---lib...........................................
|
---libjpeg.la
|
---libjpeg.so
|
---libjpeg.so.62
|
---libjpeg.so.62.0.0
--enable-shared : 用GNU libtool编译成动态链接库 。下面分别对应有无此参数所生成的Makefile的比较:
-------------------------------------------------------------------------------------------
无--enable-shared参数 | 有--enable-shared参数
-------------------------------------------------------------------------------------------
LIBTOOL = | LIBTOOL = ./libtool
-------------------------------------------------------------------------------------------
O = o A = a | O = lo A = la
-------------------------------------------------------------------------------------------
LN= $(CC) | LN= $(LIBTOOL) --mode=link $(CC)
-------------------------------------------------------------------------------------------
INSTALL_PROGRAM= ${INSTALL} | INSTALL_PROGRAM= $(LIBTOOL) --mode=install ${INSTALL}
INSTALL_LIB= ${INSTALL} -m 644 | INSTALL_LIB= $(LIBTOOL) --mode=install ${INSTALL}
-------------------------------------------------------------------------------------------------------
无参数:
# $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -c $(srcdir)/$*.c
有参数:
.c.lo:
$(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -c $(srcdir)/$*.c
----------------------------------------------------------------------------------------------------------
无参数:
install: cjpeg djpeg jpegtran rdjpgcom wrjpgcom
有参数:
install: cjpeg djpeg jpegtran rdjpgcom wrjpgcom install-lib
-----------------------------------------------------------------------------------------------------------
step3:修改生成的Makefile文件:
# The name of your C compiler:
CC= gcc 该成 CC=arm-linux-gcc (根据你自己交叉编译器的位置修改)
# library (.a) file creation command
AR= ar rc 该成 AR=arm-linux-ar rc (同上)
# second step in .a creation (use "touch" if not needed)
AR2= ranlib 该成 AR2=arm-linux-/ranlib (同上)
step4:sudo mkdir /home/jpeg_arm
sudo mkdir /home/jpeg_arm/lib
sudo mkdir /home/jpeg_arm/include
sudo mkdir /home/jpeg_arm/man
sudo mkdir /home/jpeg_arm/lib/man/man1
step5:#make
#sudo make install
这样JPEG库就交叉编译成功了,相应的库和头文件都在/home/jpeg_arm/lib和/home/jpeg_arm/include下了!
在编写应用程序在编译时记得加上 -ljpeg
--enable-static:生成静态链接库
--enable-shared:生成动态链接库
静态库
在编译过程中,就将静态库中的代码载入程序,由此生成出的可执行程序在运行中不再需要静态库,但因为库中的程序代码被复制进目标程序中,因此生成的程序体积会比较大。
linux中,静态库的命名规则通常为lib*.a
优点
·因为将库中代码加载进mysql程序中,因此运行时省去动态链接加载的过程,带来一定的性能提升
·程序运行可以不依赖于库文件,即便库文件被删除也可以照样运行
缺点
·生成的可执行程序体积较大
·使用静态链接库无法在内存中共享,会造成一定的浪费
动态库
又称为共享库,即编译时只对库进行简单的引用而不载入程序,在程序运行时才将动态库中的代码载入内存使用,因此使用动态库的程序在运行时需要其相关的动态库都存在。
linux中,动态库的命名通常是*.so
优点
·生成的可执行程序体积小
·动态库在内存只加载一次,同时可为多个进程共享,由此会提高一定的效率
缺点
·依赖库文件,不方便移植
测试数据,以下使用mysql5.1.57版本
1、 开启--enable-static
./configure--prefix=/test/static --enable-shared=no --enable-static=yes
编译大小:368M
安装大小:596M
2、 开启--enable-shared
./configure--prefix=/test/static --enable-shared=yes --enable-static=no
编译大小:352M
安装大小:566M
3、 同时开启--enable-static和--enable-shared
./configure--prefix=/test/static --enable-static --enable-shared
编译大小:387M
安装大小:617M
生成的静态库文件
[mysql@localhostdemo]$ ls static/lib/mysql/
libdbug.a libmyisammrg.a libmysqlclient_r.a libmysys.a
libheap.a libmysqlclient.a libmysqlclient_r.la libvio.a
libmyisam.a libmysqlclient.la libmystrings.a plugin
生成的动态库文件
[mysql@localhost demo]$ ls shared/lib/mysql/
libdbug.a libmysqlclient_r.so libmystrings.a
libheap.a libmysqlclient_r.so.16 libmysys.a
libmyisam.a libmysqlclient_r.so.16.0.0 libvio.a
libmyisammrg.a libmysqlclient.so plugin
libmysqlclient.la libmysqlclient.so.16
libmysqlclient_r.la libmysqlclient.so.16.0.0
同时开启两者:
[root@localhost demo]# ls both/lib/mysql/
libdbug.a libmysqlclient_r.a libmysqlclient.so.16
libheap.a libmysqlclient_r.la libmysqlclient.so.16.0.0
libmyisam.a libmysqlclient_r.so libmystrings.a
libmyisammrg.a libmysqlclient_r.so.16 libmysys.a
libmysqlclient.a libmysqlclient_r.so.16.0.0 libvio.a
libmysqlclient.la libmysqlclient.so plugin
静态编译生成的bin
[mysql@localhostdemo]$ du -sh static/bin/
24M static/bin/
动态编译生成的bin
[mysql@localhost demo]$ du -sh shared/bin/
14M shared/bin/
同时开启两者:
[root@localhost demo]# du -sh both/bin/
14M both/bin/
由此可见,生成的程序是动态链接库的,下面的测试也证明了这一点
静态编译不依赖库文件
[root@localhost demo]# cp -r static/lib/mysql/* static/lib/bak/
[root@localhost demo]# rm -rf static/lib/mysql/
[root@localhost demo]# ./static/bin/mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.57 Sourcedistribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rightsreserved.
This software comes with ABSOLUTELY NO WARRANTY. This is freesoftware,
and you are welcome to modify and redistribute it under the GPL v2license
Type 'help;' or '\h' for help. Type '\c' to clear the current inputstatement.
mysql> \q
Bye
动态编译依赖库文件
[root@localhost demo]# cp -r shared/lib/mysql/* shared/lib/bak/
[root@localhost demo]# rm -rf shared/lib/mysql/
[root@localhost demo]# ./shared/bin/mysql -uroot
./shared/bin/mysql: error while loading shared libraries:libmysqlclient.so.16: cannot open shared object file: No such file or directory
同时开启两者:
[root@localhost demo]# cp -r both/lib/mysql/* both/lib/bak/
[root@localhost demo]# rm -rf both/lib/mysql/
[root@localhost demo]# ./both/bin/mysql -uroot
./both/bin/mysql: error while loading shared libraries:libmysqlclient.so.16: cannot open shared object file: No such file or directory
--enable-assembler选项的功能是使用一些字符函数的汇编版本。那么它提升效率的原理也就不难理解了:汇编语言面向机器,直接使用CPU指令进行操作,代码简短且占用内存少。对于字符处理较多的业务能带来显著的性能提升。