rust - 在 Amazon Linux 上静态链接 ffmpeg-sys 失败,引用未定义

标签 rust rust-cargo

我的项目依赖于配置为静态构建的 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 设置为指向较新版本进行重建。

看起来 rustclibclang.so 有最低版本要求,但我找不到官方来源记录这一点。 amazon-linux安装的版本是3.6.2,明显太旧了。

关于rust - 在 Amazon Linux 上静态链接 ffmpeg-sys 失败,引用未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52341215/

相关文章:

rust - 如何让 Cargo 运行本地依赖项的测试?

rust - 是否可以禁用 Cargo 中的单个默认功能?

struct - 放入结构中时,值的生命周期不够长

build - 使用 Rust Cargo 进行构建的不同目标名称

rust - 使用 Rust 稳定版和夜间 channel 允许并行编译代码有多难?

rust - 我可以使用调试符号和发布标志来构建 cargo 吗? [复制]

rust - 使用返回与一个参数具有相同生命周期的关联类型的函数定义特征

rust - 在 Rust 中对联合进行零初始化

rust - 添加两个数字而不克隆两者

rust - 对于实现相同特征的结构,如何克服具有不兼容类型的匹配臂?