You can read this article: Load order of linux dynamic link library
The sequence of linking the so library when compiling the program is as follows:
-
The path specified by the parameter -L when gcc is compiled
gcc -o demux demuxing_decoding.c -L /usr/local/lib -lavcodec -lavformat -lavutil
-
Environment variable LIBRARY_PATH
export LIBRARY_PATH=LIBDIR1:LIBDIR2:$LIBRARY_PATH
-
System default library location /lib, /usr/lib
The sequence of finding the so library when the program is running is as follows:
-
The runtime library path specified when gcc was compiled -Wl, -rpath
-
Environment variable LD_LIBRARY_PATH
export LD_LIBRARY_PATH=LIBDIR1:LIBDIR2:$LD_LIBRARY_PATH
-
ldconfig cache /etc/ld.so.cache
vim /etc/ld.so.cache
-
System default library location /lib, /usr/lib
You can view the LIBRARY_PATH and INCLUDE paths of gcc through the following command
echo 'main(){}' | gcc -E -v -
If LIBRARY_PATH is added to ~/.bashrc, use
source ~/.bashrc
After that, it will take effect and be added to the LIBRARY_PATH of gcc. If you want to cancel this path, comment the path in ~/.bashrc and restart it .