linux dynamic library loading sequence

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:

  1. The path specified by the parameter -L when gcc is compiled

    gcc -o demux demuxing_decoding.c -L /usr/local/lib -lavcodec -lavformat -lavutil
    
  2. Environment variable LIBRARY_PATH

    export LIBRARY_PATH=LIBDIR1:LIBDIR2:$LIBRARY_PATH
    
  3. System default library location /lib, /usr/lib

The sequence of finding the so library when the program is running is as follows:

  1. The runtime library path specified when gcc was compiled -Wl, -rpath

  2. Environment variable LD_LIBRARY_PATH

    export LD_LIBRARY_PATH=LIBDIR1:LIBDIR2:$LD_LIBRARY_PATH
    
  3. ldconfig cache /etc/ld.so.cache

    vim /etc/ld.so.cache
    
  4. 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 .

Guess you like

Origin blog.csdn.net/weixin_43742643/article/details/113812481