The function and setting of Ld_library_path under Linux

Source: Internet
Author: User
Tags gtk

Symptoms

The newly written C + + program runs well on the development machine, but after being moved to a completely new machine, the connection to the shared library fails with the following information:

Pulse

The program to connect to the shared library fails, it must first determine which dynamic connection library The program uses, the better tool is LDD, check the following:

[Email protected]:/data/atp/dispatcher/bin> ldd Dispatcher         libmysqlclient.so.18 = not found        libstdc++ . so.6 =/usr/lib64/libstdc++.so.6 (0x00002ace3fcab000)        libm.so.6 =/lib64/libm.so.6 (0x00002ace3fea9000)        libgcc_s.so.1 =/lib64/libgcc_s.so.1 (0x00002ace3ffff000)        libc.so.6 =/lib64/libc.so.6 ( 0x00002ace4010c000)        /lib64/ld-linux-x86-64.so.2 (0x00002ace3fb8f000)

Library files are used when connecting (static libraries and dynamic libraries) and running (only for programs that use dynamic libraries), and their search paths are set in the system. The General Linux system takes/lib and/usr/lib as the default library search path and is in a library outside the default library search path, requiring the user to add the library location to the library's search path.

Due to the new machine, the MySQL database is the source code installation, the relevant path is specified by-prex when configure, the library file is not in the default library search path, so the program started without connecting to the corresponding dynamic library, causing the program to fail.

Prescribe medicine

After Baidu, found a Linux system environment variable Ld_library_path, is used to specify to find the dynamic library (shared library or dynamic link library) in addition to the default path other than the path. (The path is found before the default path)

When porting a program you often encounter the need to use some specific dynamic libraries, and these compiled dynamic libraries are placed in our own established directory, you can set these directories to Ld_library_path.

So, the solution comes out, just add the path where the libmysqlclient.so.18 is located to the environment variable ld_library_path . The method for setting environment variables can be consulted: http://www.cnblogs.com/sslizy/articles/4207800.html

1 out of the question

Because of a machine, the same program, may install multiple versions, each version has its own dynamic library, if a version of the library directly to the path directly in ~/.profile or ~/.BASHRC in the ld_library_path settings, May cause other programs to fail to start.

Therefore, it is recommended to reset the Ld_library_path in a program-initiated script to prevent the program from linking to other dynamic libraries, causing a variety of bizarre results or unexpected crashes, or other security issues that may exist.

2 out of the question

Online, some peers, providing another solution, the method is:

Modify the/etc/ld.so.conf file to add the search path (absolute path) of the library you use, one line at a. For example:

/usr/x11r6/lib

/usr/local/lib

/opt/lib

Then, run the/sbin/ldconfig command again to update the/etc/ld.so.config file.

However, it is not advisable for individuals to adopt such a method for the following reasons:

1. Need root permission

2, multiple versions of the program, different versions of the library, may affect other programs (compatibility)

3. When the system restarts, all GTK2-based programs will use the newly installed GTK + library at run time. Unfortunately, due to the changes in the GTK + version, this can sometimes be a compatibility issue for applications, causing some programs to run abnormally.

The function and setting of Ld_library_path under Linux

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.