Foreplay:
Have a chat today. Dynamic Link library!
Windows:dynamic? Link? Library (DLL), suffix? Xxx.dll!
Linux: is GKFX? Library. What is the suffix? xxx.so!
The simple idea is to encapsulate it as a class library, and other programs can be called dynamically.
Versatility, encapsulation, after all, some code do not want others to see.
Ps: Detailed explanation http://bbs.chinaunix.net/thread-1281954-1-1.html
Body:
- Compile the source file. C into a dynamic-link library. So
GCC-shared Me.c-o libme. so
The main program automatically adds Lib and. So suffixes based on the header file name to find the dynamic link library, which is written at compile time.
- Compile
Federated compilation:
GCC fatsnake.c me.c-o fatsnake
?
(1) compile with dynamic link library (you don't have to make all the source files)------------------------manually specify where my dynamic link library is
GCC –L /root/- l me fatsnake.c-o Fatsnake
-L Dynamic Link Library folder location
The library name of the-l dynamic-link library (removes the front lib and. So is the library name)
(2)ldd Main program name view dependency
???? LDD Fatsnake
?
Q: The reason for the failure is that the operating system cannot find libme.so???
A: In fact, like Linux and Windows, there is a system library folder similar to System32. All kinds of public libraries are put in this
There are two folders in CentOS that are similar to Windows that hold a common library
/lib Kernel level
/usr/lib User System level
The/USR/LIB64/64-bit system only
You're going to have to put your good library out of your mind. Here's a temporary demonstration. Put in the specified public library
(3) Copy to Shared Library folder: Copy the link library to the development folder
???? CP source File destination folder
???? Cp/root/libme.so/lib
(4) Reload the link library
Ldconfig
Explanation: http://blog.163.com/cn_prince/blog/static/638790120078289157270/
The main program is now associated with the link library.
?
Ps: The libme.so file in Lib is deleted, and the file runs failed! Dynamic link libraries cannot be deleted, otherwise dependencies cannot be found
????
?
End:
Today is a bit tired, fitness squat legs tired bar! A will chew book, Wash and sleep!
5. Understanding what is called dependency---dynamic link library