The difference between arm-linux-gcc static compilation and dynamic compilation

 

Many tutorials will mention that adding -static is a static compilation, but for novices it may not be easy to understand with examples. Today I will introduce an example of this knowledge:

Recently, I am working on a freetype font. I need to rely on the official library provided by freetype. I have configured the environment on the computer side. As shown below, I compiled two executable programs with -static and without -static. , The file compiled with -static is obviously much larger, because it has linked some library files that the program depends on into the file, and there is no need to rely on the library when running the program on the ARM development board. -Static runtime requires dependent libraries.

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

 Statically compiled programs can be run directly on the development board, while dynamically compiled programs are not

[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

If you need to run the program on the development board, you need to copy the library that the program depends on to the / lib directory of the development board, as shown below:

[root@iTOP-4412]# cp /mnt/udisk/lib/* /lib/ -rf -d
[root@iTOP-4412]# ./example1 ./simsun.ttc
Uniocde:
0x97e6 0x67 0x69 0x66
Unicode: 0x97e6

These dependent files need to be found in our cross-compilation tool chain, mine is under / usr / local / arm / arm-2009q3 / arm-none-linux-gnueabi / libc / lib, the path will be different in different environments , According to the actual situation.

 

Published 42 original articles · Like 10 · Visitors 10,000+

Guess you like

Origin blog.csdn.net/qq_37659294/article/details/99692418