G ++Solution to the problem that the dynamic library cannot be linked during post-Compilation:
Problem Discovery:
$
G ++-wall-O hellobrowser.exe C hellobrowser. C-I/usr/local/include
-L/usr/local/lib-lmicrohttpd-LDL
$
./Hellobrowser.exe C
Error
While loading shared libraries: libmicrohttpd. so.10: cannot open
Shared object file: no such file or directory
$
Whereis libmicrohttpd
Found/Usr/local/libThis library is available under
$
CD/usr/local/lib
$
Find libmicrohttpd. so.10
This file exists.
This is because the dynamic library defaultIt will only be found under/usr/lib. Do not search for/usr/local/lib.
Solution:
Method1:Sudo
VI/etc/lD. So. conf
Add a row:
/Usr/local/lib
ThenSudo
Ldconfig. In this way, the dynamic library will be located at/usr/local/lib.
Method2:
G ++-wall-O hellobrowser.exe C hellobrowser. c-I/usr/local/include-L/usr/local/lib-lmicrohttpd-LDL-wl,-r/usr/local/lib
Method 3:
$ Ln-S/usr/local/lib/Libmicrohttpd. so.10/Usr/lib/Libmicrohttpd. so.10
# Ln-S/usr/local/lib/Libmicrohttpd. So/usr/lib/Libmicrohttpd. So
Recommendation Method 1 and method 2.
Analysis explanation:
By default, the compiler only uses /Lib And /Usr/lib Library files under these two directories .
AlthoughG ++
-L/usr/local/lib Although the linker can find the library for link, but the runtime linker cannot find this library, if you want to make the path of the library file for the software Runtime is also extended, then we need to add this library path-Wl,-R , That is, addG ++ Parameter"-Wl,-R
Dynamic library path ".
or modify system files /etc/lD. so. conf , This file records the path of the dynamic link library used during compilation.