solution to link library not found when connecting to dynamic link library
When you link to a dynamic library, you may receive an error that cannot find the link library, and if you use the LDD command, you can see all of the dependencies of the executable file. In the "Linux C one-stop programming" book to see some solutions, first summed up the following four methods: Method A
If you are only using it temporarily in development, you can use the ld_library_path variable to set
The path of the library to which EXPORT ld_library_path= is currently dependent
This approach is only temporary and if you re-enable a terminal, you need to reset it once. Method Two
To connect a dynamic-link library is determined by the dynamic linker, you first need to know how the dynamic linker looks for the library. First look in the path recorded by the environment variable ld_library_path , if not found, proceed to the next step from the cached file /etc/ld.so.cache , under root permission, use the Ldconfig command, Read the/etc/ld.so.conf file and generate the cached file if the dynamic library is not found in either of these ways, the dynamic linker looks in the system default path, finds it in/usr/lib/, and then finds it in/lib
Then, according to the above dynamic linker Lookup library method, writes the library path to the/etc/ld.so.conf file, then runs Ldconfig (ldconfig-v can view the detailed information), can generate the cache file, the connector can find the library file method three
Copy the library file directly to the/usr/lib or/lib directory, and let the dynamic linker find method four in the system default path
When compiling with GCC, add option-wl,-rpath, the path to the dynamic library, which means that the-rpath dynamic library path is the option passed by GCC to the linker.
GCC main.c-g-L-lstack-istack-o Main-wl,-rpath, $PWD
GCC compile main.c, link dynamic library libstack.so, header file in the./stack directory, set up the library file path in the current path