zl程序教程

您现在的位置是:首页 >  后端

当前栏目

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

静态平台程序ARM 关于 动态 编译
2023-09-14 09:08:00 时间

因为近期弄个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的样子,事实上程序是非常小的一个。程序库倒是非常大一坨。