我的项目依赖于配置为静态构建的 ffmpeg-sys
crate,如下所示:
[dependencies.ffmpeg-sys]
version = "3.4.1"
default-features = false
features = ["avcodec", "avformat", "swresample", "build", "static"]
我的项目由一个简单的文件组成:
extern crate ffmpeg_sys;
use ffmpeg_sys::av_register_all;
fn main() {
unsafe { av_register_all() };
println!("Hello, world!");
}
使用 cargo build
编译时出现以下错误:
Compiling sample v0.1.0 (file:///home/ec2-user/sample)
error: linking with 'cc' failed: exit code: 1 | = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L"[... elided for clarity ...]
In function 'sample::main::hbbb19855251826d6': /home/ec2-user/sample/src/main.rs:6: undefined reference to 'av_register_all' collect2: error: ld returned 1 exit status
所需的静态库,libavformat.a
和 friend ,在target/build/debug
文件夹中找到,显示ffmpeg-sys
成功编译库。
这是失败的 rustc
命令:
Caused by: process didn't exit successfully: 'rustc --crate-name sample src/main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=250bf40eb277d05a -C extra-filename=-250bf40eb277d05a --out-dir /home/ec2-user/sample/target/debug/deps -C incremental=/home/ec2-user/sample/target/debug/incremental -L dependency=/home/ec2-user/sample/target/debug/deps --extern ffmpeg_sys=/home/ec2-user/sample/target/debug/deps/libffmpeg_sys-fa3ff87f80f2d27e.rlib -L native=/home/ec2-user/sample/target/debug/build/ffmpeg-sys-0b3c813f29a9a20e/out/dist/lib' (exit code: 1)
libffmpeg_sys-fa3ff87f80f2d27e.rlib
是 207M,因此我假设包含所有静态编译的 ffmpeg 代码。
只有当我在 Amazon Linux 实例上构建时才会发生这种情况。在我的常规 Fedora 28 桌面上编译会生成一个可用的二进制文件。
我将如何着手找出此错误的根本原因?
最佳答案
我通过构建 llvm
6.0.1 解决了这个问题,然后将 LIBCLANG_PATH
设置为指向较新版本进行重建。
看起来 rustc
对 libclang.so
有最低版本要求,但我找不到官方来源记录这一点。 amazon-linux
安装的版本是3.6.2,明显太旧了。
关于rust - 在 Amazon Linux 上静态链接 ffmpeg-sys 失败,引用未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52341215/