Linux 程序在运行时找不到共享库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4754633/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linux Program can't find Shared Library at run-time
提问by Scott
I'm trying to compile a linux program, id3v2, and it says it is can't find the appropriate library:
我正在尝试编译一个 linux 程序 id3v2,它说找不到合适的库:
id3v2: error while loading shared libraries: libid3-3.8.so.3: cannot open shared object file: No such file or directory
I'm guessing that this is the part that pulls in the lidid3 library?
我猜这是拉入liidid3库的部分?
The file DOES exist, however, what they are looking for is actually a symbolic link to:
该文件确实存在,但是,他们正在寻找的实际上是指向以下内容的符号链接:
"ibid3-3.8.so.3.0.0"
“同上3-3.8.so.3.0.0”
I'm wondering if it is an issue with it not being able to follow symbolic links? Perhaps I could manually change it to look for 0.0 if I knew where I was looking to change it.
我想知道是否是无法跟踪符号链接的问题?如果我知道我要在哪里更改它,也许我可以手动更改它以查找 0.0。
I'm happy to clarify any details.
我很高兴澄清任何细节。
It looks like the includes are done in the following manner:
看起来包含是通过以下方式完成的:
id3v2: convert.o list.o id3v2.o genre.o
${CXX} ${LDFLAGS} -pedantic -Wall -g -o $@ $^ -lz -lid3
I was able to use Simon's advice to figure out that there were multiple spots where one might expect a library. I create a symbolic link where the program was linking to the ACTUAL file.
我能够使用 Simon 的建议来确定有多个地方可能会出现一个图书馆。我创建了一个符号链接,其中程序链接到 ACTUAL 文件。
Thank you Simon!
谢谢西蒙!
采纳答案by Sdaz MacSkibbons
Symlinks on libraries work fine, as long as the final target they trace to exists and is accessible.
只要它们追踪到的最终目标存在并且可以访问,库上的符号链接就可以正常工作。
You have built a dynamically-linked executable, that wishes to be linked against libid3-3.8.so.3 at execution time. This was likely linked during the build phase with something like -L/path/to/libid3/directory -lid3
.
您已经构建了一个动态链接的可执行文件,希望在执行时链接到 libid3-3.8.so.3。这可能在构建阶段与类似-L/path/to/libid3/directory -lid3
.
You have a few optionsto make libid3
available, in generally decreasing order of preference (since you didn't mention where the file was, I can only be general):
你有几个选项,使libid3
可用,在一般递减的优先顺序(因为你没有提到该文件是,我只能算是一般):
- Create a symlink to
libid3*
in a directory listed in/etc/ld.so.conf
(or/lib
or/usr/lib
) - Copy
libid3*
to a directory listed in/etc/ld.so.conf
(or/lib
or/usr/lib
) (defaults) - Add the directory containing
libid3*
to/etc/ld.so.conf
- Set
LD_LIBRARY_PATH=/directory/path/to/libid3*
before running your id3v2 executable. - Recompile
id3v2
statically. (It will work, but don't bother.)
libid3*
在/etc/ld.so.conf
(or/lib
或/usr/lib
) 中列出的目录中创建符号链接- 复制
libid3*
到/etc/ld.so.conf
(或/lib
或/usr/lib
)中列出的目录(默认值) - 添加包含
libid3*
到的目录/etc/ld.so.conf
LD_LIBRARY_PATH=/directory/path/to/libid3*
在运行 id3v2 可执行文件之前进行设置。id3v2
静态重新编译。(它会起作用,但不要打扰。)
After any of the first 3, rerun ldconfig
so the linker cache is updated. (You can then run ldconfig -v
to verify it's resolvable.)
在前 3 个中的任何一个之后,重新运行ldconfig
以更新链接器缓存。(然后您可以运行ldconfig -v
以验证它是否可解析。)
Note those aren't steps, they're options. You only need to do 1 of them.
请注意,这些不是步骤,而是选项。您只需要执行其中的 1 个。
Glad you updated the title. #include
directives have nothing to do with linking.
很高兴你更新了标题。 #include
指令与链接无关。
回答by Kristopher Windsor
I got the same error you did, and after reading the solutions mentioned here, I resolved the problem (on Ubuntu 8) with:
我遇到了和你一样的错误,在阅读了这里提到的解决方案后,我解决了这个问题(在 Ubuntu 8 上):
sudo ln -s /usr/local/lib/libid3-3.8.so.3 /usr/lib/libid3-3.8.so.3
回答by zombocom
This solved the issue Just add /usr/local/lib to /etc/ld.so.conf (unless it's already in there; only put it once), then run ldconfig.
这解决了问题 只需将 /usr/local/lib 添加到 /etc/ld.so.conf (除非它已经在那里;只放一次),然后运行 ldconfig。