4
votes

My project depends on the ffmpeg-sys crate which is configured to build statically, as follows:

[dependencies.ffmpeg-sys]
version = "3.4.1"
default-features = false
features = ["avcodec", "avformat", "swresample", "build", "static"]  

My project consists of a single simple file:

extern crate ffmpeg_sys;

use ffmpeg_sys::av_register_all;

fn main() {
    unsafe { av_register_all() };
    println!("Hello, world!");
}

When compiling with cargo build I get the following error:

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

The required static libraries, libavformat.a and friends, are found in the target/build/debug folder, showing that ffmpeg-sys successfully compiled the libraries.

Here's the rustc command that is failing:

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 is 207M and I assume therefore contains all the statically compiled ffmpeg code.

This only happens when I build on an Amazon Linux instance. Compiling on my regular Fedora 28 desktop results in a working binary.

How would I go about figuring out the root cause of this error?

1
Compare the outputs of build.rs and see the differences. It is located at target/debug/build/<pkg>/outputattdona
"This only happens when I build on an Amazon Linux instance." have you check that the version of the linked library are the same ? (not crate version)Stargateur
The output of build.rs looks identical. The versions of the linked libraries are the same, they are retrieved from git by cargo.Tim

1 Answers

0
votes

I solved this problem by building llvm 6.0.1 and then rebuilding with LIBCLANG_PATH set to point to the newer version.

It would appear that rustc has a minimum version requirement on libclang.so, but I could not find an official source documenting that. The version installed on amazon-linux is 3.6.2 which is evidently too old.