arm |
您所在的位置:网站首页 › 编译动态库命令 › arm |
很多教程会提到加上-static是静态编译,但对于新手来说没有用例子来说明可能不太好理解,今天我就介绍一下关于这方面知识的一个例子: 最近在做一个关于freetype字体的东西,需要依赖freetype官方提供的库,我已经把电脑这边的环境配置好了,如下图,我分别用-static和不用-static编译出了两个可执行程序,用-static编译出来的文件明显大得多,因为它已经把该程序依赖的一些库文件链接到该文件里面去了,在ARM开发板上面运行该程序时不需要依赖库了,而不加-static的运行时则需要依赖的库。 root@ubuntu:/home/linuxsystemcode/04th_print_info# arm-none-linux-gnueabi-gcc -finput-charset=GBK -o example1_static example1.c -lfreetype -lm -static root@ubuntu:/home/linuxsystemcode/04th_print_info# root@ubuntu:/home/linuxsystemcode/04th_print_info# root@ubuntu:/home/linuxsystemcode/04th_print_info# ls example1.c example1_static simsun.ttc root@ubuntu:/home/linuxsystemcode/04th_print_info# arm-none-linux-gnueabi-gcc -finput-charset=GBK -o example1 example1.c -lfreetype -lm root@ubuntu:/home/linuxsystemcode/04th_print_info# ls example1 example1.c example1_static simsun.ttc root@ubuntu:/home/linuxsystemcode/04th_print_info# ls -l total 12728 -rwxr-xr-x 1 root root 13481 Aug 16 22:54 example1 -rw-r--r-- 1 root root 4698 Aug 15 19:57 example1.c -rwxr-xr-x 1 root root 2491106 Aug 16 22:53 example1_static -rw-r--r-- 1 root root 10512288 Jul 11 00:18 simsun.ttc静态编译的程序能够直接在开发板上面运行,而动态编译的则不行 [root@iTOP-4412]# ./example1_static ./simsun.ttc Uniocde: 0x97e6 0x67 0x69 0x66 Unicode: 0x97e6 ./example1 ./simsun.ttc ./example1: error while loading shared libraries: libfreetype.so.6: cannot open shared object file: No such file or directory如果需要在开发板上运行该程序则需要把该程序依赖的库拷贝到开发板的/lib目录下,如下图: [root@iTOP-4412]# cp /mnt/udisk/lib/* /lib/ -rf -d [root@iTOP-4412]# ./example1 ./simsun.ttc Uniocde: 0x97e6 0x67 0x69 0x66 Unicode: 0x97e6这些依赖文件需要到我们的交叉编译工具链里面找,我的是在/usr/local/arm/arm-2009q3/arm-none-linux-gnueabi/libc/lib下,不同的环境下路径会不一样,根据实际情况判断。 |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |