Home > System Tutorial > LINUX > body text

Linux sets dynamic library paths and environment variables

王林
Release: 2024-02-05 11:42:17
forward
1192 people have browsed it

Linux sets dynamic library paths and environment variables

After installing source compiled libraries on Linux, we need to enable the system to recognize them by default.

Assume that we have installed the library under the path /usr/local/aarch64_qt5.12.0:

1. Set the dynamic library link configuration

If dynamic library link configuration is not performed, the system will not be able to find the required *.so file, causing the software to fail to execute.

You can view dependencies by executing the ldd command, for example:

pi@NanoPi-NEO-Plus2:~$ ldd untitled
        linux-vdso.so.1 =>  (0x0000ffffba839000)
        libQt5Widgets.so.5 => not found
        libQt5Gui.so.5 => not found
        libQt5Core.so.5 => not found
        libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000ffffba7e2000)
        libstdc++.so.6 => /usr/lib/aarch64-linux-gnu/libstdc++.so.6 (0x0000ffffba653000)
        libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000ffffba5a6000)
        libgcc_s.so.1 => /lib/aarch64-linux-gnu/libgcc_s.so.1 (0x0000ffffba585000)
        libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000ffffba43e000)
        /lib/ld-linux-aarch64.so.1 (0x0000ffffba80e000)
Copy after login

The stupidest way is to copy the compiled corresponding so to /usr/lib or /lib. If there are many corresponding so, it will be a problem.

Setting method:

1) Create the dynamic library configuration file *.conf under the /etc/ld.so.conf.d path, for example:

sudo vim /etc/ld.so.conf.d/Qt5.conf

Add to the file:

/usr/local/aarch64_qt5.12.0/lib

2) Load dynamic library configuration

Execute command: sudo ldconfig

pi@NanoPi-NEO-Plus2:~$ ldd untitled
        linux-vdso.so.1 =>  (0x0000ffffa4b1a000)
        libQt5Widgets.so.5 => /usr/local/aarch64_qt5.12.0/lib/libQt5Widgets.so.5 (0x0000ffffa451d000)
        libQt5Gui.so.5 => /usr/local/aarch64_qt5.12.0/lib/libQt5Gui.so.5 (0x0000ffffa4039000)
        libQt5Core.so.5 => /usr/local/aarch64_qt5.12.0/lib/libQt5Core.so.5 (0x0000ffffa39ed000)
        libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000ffffa39c1000)
        libstdc++.so.6 => /usr/lib/aarch64-linux-gnu/libstdc++.so.6 (0x0000ffffa3832000)
        libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000ffffa3785000)
        libgcc_s.so.1 => /lib/aarch64-linux-gnu/libgcc_s.so.1 (0x0000ffffa3764000)
        libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000ffffa361d000)
        libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000ffffa360a000)
        /lib/ld-linux-aarch64.so.1 (0x0000ffffa4aef000)
Copy after login

2. Set environment variables

When executing related programs, you do not need to switch to the specified directory to execute, and can be executed in any directory.

Setting method:

1. The current session takes effect temporarily: command line input export PATH=$PATH:/usr/local/aarch64_qt5.12.0/bin

2. Permanently valid for users: vi ~/.bashrc The last line input export PATH=$PATH:/usr/local/aarch64_qt5.12.0/bin

Make environment variables effective: source .bashrc

3. Global and permanent effect:

Add a path to $PATH in /etc/profile or /etc/bash.bashrc. If the names are the same, you need to put the new path in front of other paths.

export PATH=$PATH:/usr/local/aarch64_qt5.12.0/bin

Enable environment variables to take effect: source /etc/profile

pi@NanoPi-NEO-Plus2:~$ echo $PATH
/usr/local/aarch64_qt5.12.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/
Copy after login

The above is the detailed content of Linux sets dynamic library paths and environment variables. For more information, please follow other related articles on the PHP Chinese website!

source:lxlinux.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!