(Original) how to link dynamic library during runtime after G ++ Compilation

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.