如何制作 vorbis-tools ogg123 的静态二进制构建?

如何制作 vorbis-tools ogg123 的静态二进制构建?

为了运行ogg123(从 ogg vorbis 获取 wav),我需要获取(未找到)或编译静态构建。我在 Amazon Linux 上尝试过(与当前 AWS Lambda 版本相同):

./configure --disable-shared --enable-static
make LDFLAGS=-lm SHARED=0 CC='gcc -static'

生成的ogg123文件大小为 288K,但是当我将该文件复制到另一个 Amazon Linux 并尝试运行时,我得到了 error while loading shared libraries: libvorbisfile.so.3: cannot open shared object file: No such file or directory

答案1

如果您只想wav从解码ogg vorbis,则可以简单地使用oggdec实用程序来执行此操作,而不是ogg123(它具有更多依赖项)。

要构建 的“静态”版本oggdec,您首先需要构建libogglibvorbis库的静态版本,如下所示:

#Create staging directory
STAGING=$HOME/staging/vorbis-tools
mkdir -p $STAGING

#Sources
SRC=$STAGING/src
mkdir -p $SRC

#Build artifacts
OUT=$STAGING/build
mkdir -p $OUT

#Build a static version of "libogg"
wget downloads.xiph.org/releases/ogg/libogg-1.3.1.tar.xz -qO-|tar -C $SRC -xJ
pushd $SRC/libogg*/
./configure --prefix=$OUT --disable-shared
make install
popd

#Build a static version of "libvorbis"
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.xz -qO-|tar -C $SRC -xJ
pushd $SRC/libvorbis*/
./configure --prefix=$OUT LDFLAGS="-L$OUT/lib" CPPFLAGS="-I$OUT/include" --disable-shared
make install
popd

现在您可以构建oggdec(vorbis-tools),静态链接到libogglibvorbis

#Build "vorbis-tools"
wget downloads.xiph.org/releases/vorbis/vorbis-tools-1.4.0.tar.gz -qO- | tar -C $SRC -xz
pushd $SRC/vorbis-tools*/
./configure LDFLAGS="-L$OUT/lib" CPPFLAGS="-I$OUT/include"
make
popd

您可以使用LDD,检查新构建的oggdec二进制文件的依赖项列表:

ldd $SRC/vorbis-tools*/oggdec/oggdec

linux-vdso.so.1 (0x00007ffc85792000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fbcba839000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fbcba48e000)
/lib64/ld-linux-x86-64.so.2 (0x00007fbcbab3a000)

生成的二进制文件并不是真正完全“静态”的,因为它仍然公开对某些系统库(特别是“libc”和“libm”)的依赖关系,但这应该适合在“Amazon Linux”下运行它。

相关内容