在 conda 环境中使用前缀进行 ./configure 后,ffmpeg 无法加载共享库

问题描述 投票:0回答:1

我正在使用

conda
并在该环境中从源代码构建 ffmpeg。

我运行了以下命令:

conda create --name my_conda_env
conda activate my_conda_env
# Now I am in the conda environment
# $CONDA_PREFIX is /home/myuser/.conda/envs/my_conda_env/bin/ffmpeg

# Checkout ffmpeg code
# git checkout ...

./configure --prefix=$CONDA_PREFIX --enable-shared --disable-static && make distclean && make -j 100 && make install

# The above command does install the newly built ffmpeg into:
# /home/myuser/.conda/envs/my_conda_env/bin/ffmpeg

# However it fails to execute:
ffmpeg
ffmpeg: error while loading shared libraries: libavdevice.so.58: cannot open shared object file: No such file or directory

# When I add the conda lib path to LD_LIBRARY_PATH it works:
LD_LIBRARY_PATH=$CONDA_PREFIX/lib:$LD_LIBRARY_PATH ffmpeg
ffmpeg version n4.2.9-4-gd7beb0c61f Copyright (c) 2000-2023 the FFmpeg developers

# I thought ./configure with a --prefix will build a binary that will search for libraries relative to itself, but that does not appear to be the case:

strace -o /tmp/strace.out ffmpeg
tail /tmp/strace.out

openat(AT_FDCWD, "/usr/lib64/haswell/x86_64/libavdevice.so.58", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/lib64/haswell/x86_64", 0x7fff65f56d90, 0) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib64/haswell/libavdevice.so.58", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/lib64/haswell", 0x7fff65f56d90, 0) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib64/avx512_1/x86_64/libavdevice.so.58", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/lib64/avx512_1/x86_64", 0x7fff65f56d90, 0) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib64/avx512_1/libavdevice.so.58", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/lib64/avx512_1", 0x7fff65f56d90, 0) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib64/x86_64/libavdevice.so.58", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/lib64/x86_64", 0x7fff65f56d90, 0) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib64/libavdevice.so.58", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/lib64", {st_mode=S_IFDIR|0555, st_size=49526, ...}, 0) = 0
writev(2, [{iov_base="ffmpeg", iov_len=6}, {iov_base=": ", iov_len=2}, {iov_base="error while loading shared libra"..., iov_len=36}, {i
ov_base=": ", iov_len=2}, {iov_base="libavdevice.so.58", iov_len=17}, {iov_base=": ", iov_len=2}, {iov_base="cannot open shared object file", iov_len=30}, {iov_base=": ", iov_len=2}, {iov_base="No such file or directory", iov_len=25}, {iov_base="\n", iov_len=1}], 10) = 
123

Conda 文档说不要在这里使用 LD_LIBRARY_PATH:

https://docs.conda.io/projects/conda-build/en/stable/resources/use-shared-libraries.html#shared-libraries-in-macos-and-linux

如何在 conda 环境中从源代码构建 ffmpeg 并让二进制文件找到相对于自身的 .so 文件?

ffmpeg conda configure
1个回答
0
投票

我找到了答案:

./configure ... --enable-rpath

启用 rpath 并且二进制文件会查找相对于自身的 .so 文件。

© www.soinside.com 2019 - 2024. All rights reserved.