./hehe.c: error while loading shared libraries: libjpeg.so.9: cannot open shared object file: No such file or directory
編譯命令 gcc -o hehe.c hehe.c -ljpeg 成功,但執行時找不到動態庫。
編譯鏈接階段只需庫文件存在於 /usr/local/lib,但運行時動態鏈接器需在運行時搜索路徑中找到 .so 文件。默認搜索路徑不包含 /usr/local/lib。
gcc -o hehe hehe.c -L/usr/local/lib -ljpeg -Wl,-rpath=/usr/local/lib
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
/etc/ld.so.conf.d/usr-local-lib.conf 添加路徑,執行 ldconfigldd ./hehe # 查看動態庫依賴路徑