关于静态与动态编译arm平台程序的比较

来源:互联网 发布:限制手机使用时间软件 编辑:程序博客网 时间:2024/05/22 06:32

由于最近弄个console程序,调用了readline,ncurses库,这两个动态库加起来有四百多k,而程序其实很小,其他地方也没使用到这两个库

所以想静态编译看看console程序有多大。

#arm-linux-gcc cli.c -o console libreadline.a  libncurses.a

 #ls -l

total 1932
-rwxrwxr-x 1 root root   8427 Jul  7 15:19 cli
-rw-r--r-- 1 root root   6647 Jul  7 17:57 cli.c
-rwxr-xr-x 1 root root 624681 Jul  8 15:00 console
-rw-r--r-- 1 root root 108398 Jul  7 16:05 libhistory.a
-rw-r--r-- 1 root root 433720 Jul  7 17:09 libncurses.a
-rw-r--r-- 1 root root 780788 Jul  7 16:05 libreadline.a

一看有六百多k,貌似大了点,加上-s试试

# arm-linux-gcc cli.c -o console libreadline.a  libncurses.a  -s

# ls -l
total 1576
-rwxrwxr-x 1 root root   8427 Jul  7 15:19 cli
-rw-r--r-- 1 root root   6647 Jul  7 17:57 cli.c
-rwxr-xr-x 1 root root 259323 Jul  8 15:03 console
-rw-r--r-- 1 root root 108398 Jul  7 16:05 libhistory.a
-rw-r--r-- 1 root root 433720 Jul  7 17:09 libncurses.a
-rw-r--r-- 1 root root 780788 Jul  7 16:05 libreadline.a

剩下260多k这样,貌似能接受。


回过来再看看动态库链接下的console程序

#arm-linux-gcc cli.c -o console -lreadline -lncurses 

# ls -l
total 1332
-rwxrwxr-x 1 root root   8427 Jul  7 15:19 cli
-rw-r--r-- 1 root root   6647 Jul  7 17:57 cli.c
-rwxr-xr-x 1 root root  10445 Jul  8 15:12 console
-rw-r--r-- 1 root root 108398 Jul  7 16:05 libhistory.a
-rw-r--r-- 1 root root 433720 Jul  7 17:09 libncurses.a
-rw-r--r-- 1 root root 780788 Jul  7 16:05 libreadline.a

10.2k的样子,加上动态库也就四百多k


再进一步加上-s试试

#arm-linux-gcc cli.c -o console -lreadline -lncurses -s

# ls -l
total 1328
-rwxrwxr-x 1 root root   8427 Jul  7 15:19 cli
-rw-r--r-- 1 root root   6647 Jul  7 17:57 cli.c
-rwxr-xr-x 1 root root   6839 Jul  8 15:13 console
-rw-r--r-- 1 root root 108398 Jul  7 16:05 libhistory.a
-rw-r--r-- 1 root root 433720 Jul  7 17:09 libncurses.a
-rw-r--r-- 1 root root 780788 Jul  7 16:05 libreadline.a

6.7k的样子,其实程序是很小的一个,程序库倒是很大一坨。










0 0
原创粉丝点击