linux 程序运行时,提示找不到 xx.so.x,如何查询linux程序需要哪些库,linux链接库的...
source link: https://blog.popkx.com/when-the-linux-program-runs-the-prompt-can-not-find-xx-so-x-how-to-query-the-linux-program-needs-which-libraries-linux-link-libr/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
linux 程序运行时,提示找不到 xx.so.x,如何查询linux程序需要哪些库,linux链接库的添加方法
问题原因查找
今天打算再linux中运行 test.out 程序时,提示
# ./test.out
./test.out: can't load library 'libfreetype.so.6'
出现这种提示有两种可能,一是确实没有这个库,再就是有这个库,但是运行程序时,系统不知道去哪里找这个库。于是,执行ldd
命令,可以看到:
# ldd test.out
...
libfreetype.so => /usr/local/lib/libfreetype.so(0x00007f767af0a000)
...
也在预料中,很多库都会在这个目录里。
可以将该路径加入环境变量:
export PATH=/usr/local/lib:$PATH
再次运行,依然报同样的错误。稍稍思考一下,知道应该将该路径加入LD_LIBRARY_PATH
环境变量里,这个环境变量看其名字就知道是专为库设置的。
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
再次运行,发现 test.out 程序正常运行了。
将环境变量加入 bashrc
之所以进行这一步,是因为 export
命令只对当前终端起作用,关闭该终端,再打开,就必须再次执行export
一次,这样就显得比较麻烦。所以可以将export
加入bashrc
文件,这样每次打开终端,系统会自动执行export
,就一劳永逸了。
sudo vim ~/.bashrc
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH # 在文件最后加入
source ~/.bashrc
阅读更多: Linux笔记
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK