linux dynamic and static libraries

First: We need to know the characteristics of dynamic and static libraries of
static library: .a
dynamic library: .so
common libadd.a libadd.so
dynamic libraries: the goal compiled into a special binary program itself can not be executed directly, but can be called scene: the client only update a module more
static link library: to generate a series of special binary file with the .o file itself can not be executed, but others can be a .c file compiled into a new executable program

Here Insert Picture Description

Build a dynamic library

Here Insert Picture Description

Here Insert Picture Description

Here Insert Picture Description

Here Insert Picture Description

In fact, the above code can simply write for the general dependence but generate static library that the use of a large number of dependent role becomes more important, others can use your .a file directly,

To look at the dynamic of
Here Insert Picture Description

Here Insert Picture Description

We do not see libadd.so but the target file can be used to perform

Building a dynamic library of commands: gcc -test.c -shared -fPIC -o libadd.so

                                 ldd  可以查看一个可执行程序依赖了哪些动态库 
                                 LD_LIBRARAY_PATH     设定环境变量 去提醒系统去哪找

C ++ source code of third-party libraries need to be compiled into a static library / dynamic library to use because of environmental differences compilation, this process is not sincere pain

Published 90 original articles · won praise 13 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_44030580/article/details/103558478