-
Notifications
You must be signed in to change notification settings - Fork 253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow inclusion in static builds #2690
Comments
It seems a local problem. You seem to be missing a base library. |
Yeah I do have |
Ref: https://packages.ubuntu.com/search?searchon=contents&keywords=libgcc_s.a&mode=filename&suite=focal&arch=amd64 (the few results are only mingw, which probably isn't really helpful in this instance) |
If you look it up, you see a lot of people suggesting liking it dynamically, which isn't quite possible here, because it's defined via pkgconfig: https://stackoverflow.com/a/18803598/8220327 |
For reference the generated
|
I see in https://askubuntu.com/a/1190778 that someone recommends removing the rav1e shared library to build ffmpeg. We should look into why this workaround is necessary for some configurations. |
I'm actually building without shared libraries:
I did not see any difference vs not doing that though |
To be clear: If I'm not linking it statically it's working just fine, it's only having problems while linking statically |
FWIW I double checked and on Fedora Linux and my .pc also has -lgcc_s. I did notice there is a -static-libgcc option to gcc, however I've not tested it. (I'm also not sure why rav1e depends on libgcc_s...)
|
I tested |
I note that |
It seems to be target at Windows though so there might be a difference there (likely using mingw, which seems to bring a static version of libgcc_s) |
Apparently Rust's own unwinder normally depends on libgcc_s. I'm not sure if we can disable the unwinder (or would even want to - it probably requires abort on panic), though I did find this option for using libunwind instead, which might be easier to statically link. Maybe we should do this by default. rust-lang/rust#59089 |
Even if not by default (one probably should benchmark it and look at the consequences for compilation and usage), it might make sense to add it as an option if that's possible |
You should open the issue on the rust side, we receive the link line directly from the compiler. |
But is it the compiler though or the |
So I tested and this works as a workaround (I haven't tested a panic though):
|
It is the compiler |
Okay do you want to report it or should I? Because I don't really have experience and probably can't really provide Infos to them |
Just so I can mess around with this a bit, are you statically linking libc as well? If so, which libc and/or target triple are you using? |
I'm not entirely sure, I think it is, but I can provide you with a little shell script that should be able to reproduce it |
libc is probably gcc default, so |
You can download this, put it into an empty dir and execute it and it'll download ffmpeg and rav1e (into the folder of the script) and compile both locally with the prefix set to repro.sh#!/bin/bash
set -e
cd "$(dirname "${0}")"
prefix="$(pwd)/prefix"
mkdir -p "${prefix}"
export CFLAGS="$CFLAGS -O3" CXXFLAGS="$CFLAGS"
export LDFLAGS="$LDFLAGS -L${prefix}/lib"
export LD_LIBRARY_PATH="${prefix}/lib"
export PKG_CONFIG_PATH="${prefix}/lib/pkgconfig"
ffmpeg_version="4.3.2"
rav1e_version="0.4.0"
echo "Fetching repositories..."
if [[ -d rav1e ]]; then
pushd rav1e
git fetch
else
git clone https://github.com/xiph/rav1e.git rav1e
pushd rav1e
fi
git checkout "v${rav1e_version}"
popd
if [[ -d ffmpeg ]]; then
pushd ffmpeg
git fetch
else
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
pushd ffmpeg
fi
git checkout "n${ffmpeg_version}"
popd
echo "Building rav1e..."
pushd "rav1e"
echo " - Building..."
RUSTFLAGS="-C target-cpu=native" cargo cinstall --release --locked --prefix "${prefix}" --library-type staticlib
# tmp fix, because static build fails
#echo " - Fixing static build..."
#mv "${prefix}/lib/pkgconfig/rav1e.pc" "${prefix}/lib/pkgconfig/rav1e.pc.orig"
#sed 's/ -lgcc_s/ /g' "${prefix}/lib/pkgconfig/rav1e.pc.orig" >"${prefix}/lib/pkgconfig/rav1e.pc"
#rm "${prefix}/lib/pkgconfig/rav1e.pc.orig"
popd
echo "Building ffmpeg..."
pushd ffmpeg
echo " - Configuring..."
./configure \
--prefix="${prefix}" \
--extra-libs="-lm -lpthread" \
--pkg-config-flags="--static" \
--extra-cflags="-I${prefix}/include -static -w -O3" \
--extra-ldflags="-static" \
--disable-runtime-cpudetect \
--disable-doc \
--disable-pic \
--disable-shared \
--enable-static \
--disable-autodetect \
--disable-ffplay \
--disable-ffprobe \
--disable-debug \
--enable-librav1e
echo " - Building..."
make clean
make -j "$(nproc)"
popd The configuration log of ffmpeg (with that error) can be found at The resulting binary will be at |
With the workaround I get:
So I guess libc is statically linked. |
Please do and also open an issue on |
Can you give me more info on where the compiler generates the list of libraries, so I can report something substantial to them? |
If you run on a crate with
You'd get:
For rav1e you'd have to add the crate types to Cargo.toml like this: diff --git a/Cargo.toml b/Cargo.toml
index 65b87ef4..fc1bfa52 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -138,6 +138,7 @@ required-features = ["binaries", "channel-api", "unstable"]
bench = false
[lib]
+crate-type = ["staticlib", "rlib", "cdylib"]
bench = false
[[bench]]
I confirm that |
Filed a report for the compiler, I'll see what's the result of that and then I think be can look into whether there's something to be done on the cargo-c part of it. |
Can we consider the problem now solved? |
I'm trying to build a static version ffmpeg including rav1e, but it seems like one can't compile a static library that includes
lgcc_s
, because there's only a shard version of it.I'm not a lot into C so I'm not sure if that is something that even can be changed at all or if there's something I couldn't find that's allows this (although I searched quite thorough and all of the "solutions" simply didn't work or aren't applicable).
The text was updated successfully, but these errors were encountered: