The order of the connector ld link in Linux system is very important. If the order is not correct, it will cause the undefined referenced function to report an error. The following small series will introduce you how to arrange the connection under Linux. The order in which ld is linked.
ld original order for a series of link library is very sensitive, otherwise it will report an error function symbol undefined referenced, meaning that the function definition is not found. In fact, the library can be opened correctly. If the library libA.a depends on the library libB.a, then the connector's argument should be ln -lA -lB, which must be written like this. Otherwise it will be wrong.
This seems to be a legacy of history. To put it bluntly, if you determine that a library is not important, it is put to the end, that is, the order in which the libraries are loaded is in order, from left to right, with the highest priority, which is why the machines in the ancient times were too broken. The internal and hard drives including the CPU are extremely rare and precious. So you need to get what you need in advance and don't need it. Once you need it, load it up. Don't load it if you don't need it. This can explain the above error, the compiler loaded into socketcomm, found that there is a dependency library, and then look for it, there is a flaw, so it is wrong.
In other words, the dependencies are placed as far as possible so that everyone can share them.
This leads to another problem. If there are multiple libraries, using the same function name or class name, what happens to the structure name?
You can use nm and readelf, ldd and other commands to view your library's dependencies and symbol tables and exported function symbols. This will allow you to verify the different compilation results above because of the order.
Divide the test library into dynamic and dynamic; static and static;
The first case: the static library contains the same name function
The code is as follows:
gcc -L./main.c -lA -lB
Compile error, in multiple definition of `XXX‘. Repeat the definition function.
The second case: the moving library
This depends on the order of loading, as mentioned above, starting from the left, loading as needed.
The code for the code is as follows:
gcc main.c . /libB.so . /libA.so
The code for the code is as follows:
gcc main.c . /libA.so . /libB.so
Such a link is implicitly linked, or a load-time link, while the previous static library is a compile-time connection.
That is, the order of compilation determines which library in the library is called with the same name.
The third case: moving, but dynamic loading, not the static loading above.
The code for the code is as follows:
gcc main.c -ldl . /libA.so . /libB.so
The code for the code is as follows:
gcc main.c -ldl . /libB.so . /libA.so
When there is no link option, it is the same as the second case. After adding the L option, specify which one to load.
libB is a static link! , libA is dynamically loaded.
The code of the code is as follows:
gcc -L./main.c -ldl –lB
The library name of the dynamic library is displayed in the compile option. >
The code for the code is as follows:
gcc -L./main.c -ldl -lB . /libA.so
The code for the code is as follows:
gcc -L./main.c -ldl . /libA.so -lB
When there is static and dynamic, do not add the dynamic library library name to the compile option, the output is normal, if added, the static library is mainly related to the link order.
The above is the introduction of the ld link order of the connector under Linux system. Different order will result in different compilation results. Therefore, it should be placed as far as possible after the dependency. Do you remember?
In the Ubuntu system, the system can be remotely booted by simple setup, that is, w
In Linux systems, the Mogilefs Distributed Storage System can be used to store images and automatica
Those who have used the Linux operating system know that the file transfer between Linux system and
As a Linux system administrator, you need to manage the system user accounts regularly, and delete u
Steps for Linux to build a static link library
Linux can not identify the u disk solution
What should I do if the NIC cannot be started after the Linux virtual machine is cloned?
Linux version of the command to install BleachBit Daquan
How to use sudo command to increase permissions under Linux system
How to install and configure DenyHosts tool
Linux system 11 terminal commands that cannot be known
Ways to view and modify DNS configuration in Linux
Linux installation of PCNS software
Linux command line daily use technology
What should I do if the U disk file is read-only on Ubuntu and cannot be deleted?
Windows7 system boot settings automatically connected to the network
How to do win7 optical drive can not be used
Windows 8 and iTunes marriage failed
How Linux Systems Monitor Mogilefs Storage Nodes
Win10 uses the edge to browse the website when prompted to open with IE. What should I do? The
Win7 system open IE browser prompt certificate is not recognized, what should I do?
How does the Win8 system add Bluetooth to the "send to" option in the context menu?