enable-assembler,--enable-static,--enable-shared编译项的研究 .

来源:互联网 发布:php static global 编辑:程序博客网 时间:2024/05/29 10:21

--enable-static与--enable-shared

--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

       --enable-assembler选项的功能是使用一些字符函数的汇编版本。那么它提升效率的原理也就不难理解了:汇编语言面向机器,直接使用CPU指令进行操作,代码简短且占用内存少。对于字符处理较多的业务能带来显著的性能提升

0 0
原创粉丝点击