mpv-player / mpv-build

🔨 Helper scripts to compile mpv on Linux
http://mpv.io
414 stars 108 forks source link

Linker error with libmpv #160

Closed nathanfranke closed 3 years ago

nathanfranke commented 3 years ago

Build script:

echo "--enable-static" > ffmpeg_options
echo "--enable-libmpv-static" > mpv_options

CFLAGS="-fPIC" ./rebuild
#include <mpv/client.h>

int main() {
        mpv_create();
        return 0;
}
$ gcc -lmpv test.c
/usr/bin/ld: /tmp/ccNrCLHp.o: in function `main':
test.c:(.text+0x9): undefined reference to `mpv_create'
collect2: error: ld returned 1 exit status
CounterPillow commented 3 years ago

you want lower case l, not upper case L.

-L adds a library search path. -lfoo links a library named "libfoo"

nathanfranke commented 3 years ago

you want lower case l, not upper case L.

-L adds a library search path. -lfoo links a library named "libfoo"

thanks but I get the same behaviour with -lmpv

avih commented 3 years ago

echo "--enable-libmpv-static" > mpv_options

This will make the build attempt to link everything statically, but I don't think it guarantees that libmpv ends up fully static, because it will only link statically libs which you have static on your system.

So you need to also use pkg-config to get the C flags/libs which libmpv requires.

avih commented 3 years ago

I assume you figured it out.

nathanfranke commented 3 years ago

I am not sure what I am supposed to do with pkg-config. If I try to run pkg-config --libs --cflags ./build_libs/lib/pkgconfig/libpostproc.pc with almost any library it says something like this:

Package dependency requirement 'libavutil >= 57.0.100' could not be satisfied.
Package 'libavutil' has version '56.70.100', required version is '>= 57.0.100'

Even if I link to every library in mpv/build/libmpv/mpv.pc, Libs.private and these CFLAGS:

-fPIC -L./build_libs/lib -Wl,-Bstatic -lavutil -lswscale -lavcodec -lswresample -llua5.2 -lcaca -ldrm -lEGL -lgbm -lwayland-egl -ljack -lpthread -ljpeg -llcms2 -larchive -lass -lavdevice -lxcb -lxcb-shm -lxcb-shape -lxcb-xfixes -lasound -lSDL2 -lavfilter -lswscale -lpostproc -lavformat -lbz2 -lgnutls -lavcodec -llzma -lswresample -lavutil -lbluray -ldl -lm -lplacebo -lrt -lpulse -lshaderc_shared -lva-drm -lva-wayland -lva-x11 -lva -lvdpau -lvulkan -lwayland-client -lwayland-cursor -lxkbcommon -lX11 -lXss -lXext -lXinerama -lXrandr -lXv -lzimg -lz

The result library libmpv.a is essentially unchanged (Still 13.8MiB)

My complete build script: ``` #!/bin/bash set -e export LC_ALL=C cd "$(dirname "$0")/mpv-build" echo "--enable-static" > ffmpeg_options echo "--enable-libmpv-static" > mpv_options ./update ./clean #scripts/fribidi-config #scripts/fribidi-build $@ scripts/libass-config scripts/libass-build $@ scripts/ffmpeg-config scripts/ffmpeg-build $@ export CFLAGS="-fPIC -L$(pwd)/build_libs/lib -Wl,-Bstatic -lavutil -lswscale -lavcodec -lswresample -llua5.2 -lcaca -ldrm -lEGL -lgbm -lwayland-egl -ljack -lpthread -ljpeg -llcms2 -larchive -lass -lavdevice -lxcb -lxcb-shm -lxcb-shape -lxcb-xfixes -lasound -lSDL2 -lavfilter -lswscale -lpostproc -lavformat -lbz2 -lgnutls -lavcodec -llzma -lswresample -lavutil -lbluray -ldl -lm -lplacebo -lrt -lpulse -lshaderc_shared -lva-drm -lva-wayland -lva-x11 -lva -lvdpau -lvulkan -lwayland-client -lwayland-cursor -lxkbcommon -lX11 -lXss -lXext -lXinerama -lXrandr -lXv -lzimg -lz" scripts/mpv-config scripts/mpv-build $@ rm *_options ```