# Cross-compilation, static binaries and ffmpeg

Hi!

I'm trying to cross-compile a rust-ffmpeg example from linux x86_64 to x86_64-pc-windows-gnu, and then execute it.
The compilation process works flawlessly, but then I get errors such as 0158:err:module:import_dll Library avcodec-59.dll (which is needed by L"Z:\\path\\to\\metadata.exe") not found, which pretty explicitly means that the static linking failed.

The command I tried to run is:
CARGO_FEATURE_STATIC=foo FFMPEG_DIR=/path/to/precompiled/ffmpeg/windows/ffmpeg cargo build --release --example=metadata --target x86_64-pc-windows-gnu --verbose --features=static

What bugs me is that looking at the rustc execution, it seems that it should work (pasted on an external website because it's huge Past-isserie).

The important part seem to be there: the rust-ffmpeg-sys crate is compiled with

-l static=avcodec -l static=avdevice -l static=avfilter -l static=avformat -l static=avutil -l
static=swresample -l static=swscale


And the path to the lib is correct: -L native=/home/polochon/Documents/Programming/Rust/bliss-rs/ffmpeg/lib.

It then creates a .rlib file, that ffmpeg-next should in turn be able to statically link correctly.

I can't seem to find the reason why this doesn't statically link ffmpeg. Any help or suggestions would be greatly appreciated

Cheers!

Avcodec is likely not available as static library. Does the ffmpeg install dir contain a file like avcodec.lib? You could also try if not passing FFMPEG_DIR and instead letting it build ffmpeg itself helps.

You're right! I've asked around to the folks at #ffmpeg on libera, and the precompiled shared binaries don't allow to make fully static binaries (or the archives would weigh 500Mb more than what they currently do).

The solution is then to cross-compile ffmpeg myself using --disable-shared and --enable-static, but it is not really realistic.

Anyways, this is not a rust problem, so I'll mark this as solved, but thought maybe future people would be interested in seeing this

If you only need audio decoding, I suggest using Symphonia instead of FFmpeg and save yourself the pain of cross compiling C.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.