The library has both dynamic and static. Dynamics usually use .so as the suffix and static as the .s. For example: libhello.so libhello.a
In order to use different versions of the library in the same system, you can add the version number to the suffix after the library file name, for example: libhello.so.1.0, due to program connection default Use .so as the file extension. So in order to use these libraries, it is common to use a way to establish symbolic connections.
ln -s libhello.so.1.0 libhello.so.1ln -s libhello.so.1 libhello.so using the library
When you want to use a static library, the connector will find the program The required functions are then copied to the executable file. Since this copy is complete, once the connection is successful, the static library is no longer needed. However, this is not the case with dynamic libraries. The dynamic library will leave a mark in the executor & lsquo; indicates that when the program is executed, the library must first be loaded. Since the dynamic library saves space, the default operation for connecting under Linux is to connect the dynamic library first, that is, if there are static and dynamic libraries at the same time, if it is not specified, it will be connected with the dynamic library.
Now suppose there is a program development package called hello, which provides a static library libhello.a a dynamic library libhello.so, a header file hello.h, the header file provides sayhello() function
/* hello.h */void sayhello();
There are also some documentation. This is a typical program development package structure
1. Connect with the dynamic library
linux default is to connect with the dynamic library, the following program testlib.c uses the sayhello() in the hello library Function
/*testlib.c*/#include#includeint main(){sayhello();return 0;}
Compile with the following command
$gcc -c testlib.c -o testlib.o
Connect with the following command:
$gcc testlib.o -lhello -o testlib
Note that when connecting, assume that both libhello.so and libhello.a are in the default library search path /usr/Under lib, if you want to add -L parameter to other locations
2. Connect with static library
It is troublesome to connect with static library, mainly parameter problem. Or the above example:
$gcc testlib.o -o testlib -WI,-Bstatic -lhello
Note: This special "-WI,-Bstatic" parameter is actually passed to the connector ld Indicates that it is connected to a static library. If there is only a static library in the system, of course, this parameter is not needed.
If you want to connect with multiple libraries, and each library is connected differently, for example, the above program should be statically connected with libhello and dynamically connected with libbye. The command should be:
$gcc testlib.o -o testlib -WI,-Bstatic -lhello -WI,-Bdynamic -lbye
3. Path problem for dynamic libraries
In order for the executable to find the dynamic library smoothly, There are three ways:
(1) Copy the library to the /usr/lib and /lib directories.
(2) Add the path of the library in the LD_LIBRARY_PATH environment variable. For example, the dynamic library libhello.so is in the /home/ting/lib directory, using bash as an example. Use the command:
$export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/ting/lib
(3) Modify /etc/The ld.so.conf file adds the path where the library resides to the end of the file and performs an ldconfig refresh. In this way, all the library files in the added directory are visible
4. View the symbols in the library
Sometimes it may be necessary to check which functions are in a library, the nm command can print out the library. All the symbols involved. Libraries can be either static or dynamic. There are many symbols listed in nm, there are three common ones, one is called in the library, but not defined in the library (indicating that other library support is needed), represented by U; one is the function defined in the library, This is the most common with T; the other is the so-called "weak" symbols, which are defined in the library but may be covered by symbols of the same name in other libraries, denoted by W. For example, suppose the developer wants to know if printf() is defined in the hello library mentioned in the previous section:
$nm libhello.so
disk partitioning under Linux, file system formatting and raid devicecomparing disk partition format
AWK Stands for ‘Aho, Weinberger, and Kernighan‘Awk is a scripting language which is use
In the adb shell terminal, enter ps, you can view all current process status of the phone, where the
1 Start vSphere Client2 Start Virtual Machine [Right-click on VM, select Power —>Open] and
Linux printf output string color
Linux VMware (virtual machine) can not automatically obtain the IP address (solution)
Modify IP, DNS, and routing configuration under Linux
View the method of linux server traffic summary
Neighbor subsystem of linux protocol stack (garbage collection seven)
Getting Started with Linux Commands: Basics of System Security Commands
Bzip2: Data integrity error when decompressing
A simple way to implement FTP virtual host under Linux system
Get the current system time with C under Linux
Computer master repair hard disk logic bad track has a coup
How to fix the WinXP network connection?
Combined with the example analysis, the boot screen saver cannot display the fault
Windows 7 method of creating a library
Folder privacy You need DOS to command daemon
0x800F0A12 error code appears reason
Several factors to consider when upgrading your server hardware
Win10 Build 10176 game compatible complete list: tends to perfect