fraunhoferhhi / vvdec

VVdeC, the Fraunhofer Versatile Video Decoder
https://www.hhi.fraunhofer.de/en/departments/vca/technologies-and-solutions/h266-vvc.html
BSD 3-Clause Clear License
458 stars 91 forks source link

Android Linking Problem #200

Open K-os opened 2 days ago

K-os commented 2 days ago

Originally posted by @MartinEesmaa in https://github.com/fraunhoferhhi/vvdec/issues/198#issuecomment-2395778005 :

          Hey guys! I got also problem too when I found out that exception error code when configuring my custom FFmpeg repo:

Last twenty lines of ffbuild/config.log:

ld.lld: error: undefined symbol: std::__ndk1::basic_iostream<char, std::__ndk1::char_traits<char>>::~basic_iostream()
>>> referenced by sstream:1102 (/home/martineesmaa/mpv-android-vvc/buildscripts/sdk/android-ndk-r27b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/sstream:1102)
>>>               DecLib.cpp.o:(vvdec::DecLib::create(int, int, vvdec::UserAllocator const&, vvdec::ErrHandlingFlags)) in archive /home/martineesmaa/mpv-android-vvc/buildscripts/prefix/arm64/lib/libvvdec.a
>>> referenced by sstream:1010 (/home/martineesmaa/mpv-android-vvc/buildscripts/sdk/android-ndk-r27b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/sstream:1010)
>>>               vvdecimpl.cpp.o:(std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>::basic_stringstream[abi:ne180000]()) in archive /home/martineesmaa/mpv-android-vvc/buildscripts/prefix/arm64/lib/libvvdec.a
>>> referenced by sstream:1102 (/home/martineesmaa/mpv-android-vvc/buildscripts/sdk/android-ndk-r27b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/sstream:1102)
>>>               vvdecimpl.cpp.o:(std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>::~basic_stringstream()) in archive /home/martineesmaa/mpv-android-vvc/buildscripts/prefix/arm64/lib/libvvdec.a

ld.lld: error: undefined symbol: std::__ndk1::basic_ios<char, std::__ndk1::char_traits<char>>::~basic_ios()
>>> referenced by sstream:1102 (/home/martineesmaa/mpv-android-vvc/buildscripts/sdk/android-ndk-r27b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/sstream:1102)
>>>               DecLib.cpp.o:(vvdec::DecLib::create(int, int, vvdec::UserAllocator const&, vvdec::ErrHandlingFlags)) in archive /home/martineesmaa/mpv-android-vvc/buildscripts/prefix/arm64/lib/libvvdec.a
>>> referenced by sstream:1103 (/home/martineesmaa/mpv-android-vvc/buildscripts/sdk/android-ndk-r27b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/sstream:1103)
>>>               DecLib.cpp.o:(vvdec::Exception& vvdec::Exception::operator<<<char [78]>(char const (&) [78])) in archive /home/martineesmaa/mpv-android-vvc/buildscripts/prefix/arm64/lib/libvvdec.a
>>> referenced by sstream:901 (/home/martineesmaa/mpv-android-vvc/buildscripts/sdk/android-ndk-r27b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/sstream:901)
>>>               DecLib.cpp.o:(vvdec::Exception& vvdec::Exception::operator<<<char [78]>(char const (&) [78])) in archive /home/martineesmaa/mpv-android-vvc/buildscripts/prefix/arm64/lib/libvvdec.a
>>> referenced 466 more times

I think exception code may be problem, which may be not able to configure probably on native systems, but I'm not too sure...

Feel free to ask or reply to me. Thanks! :)

  • Martin Eesmaa

@adamjw24 replied :

Looks like a linking problem, see https://stackoverflow.com/questions/49183886/error-undefined-reference-to-std-ndk1localelocale

Seems you are mixing up the libstdc++ implementations.

@MartinEesmaa wrote :

Hi, @adamjw24! Thank you for your response back! :)

I already tried to compile with c++_shared with ANDROID_STL.

So here is my CMake configuration before FFmpeg configuration:

cmake \
       -DCMAKE_BUILD_TYPE=Release -DANDROID_ABI=$ndk_vvdec \
      -DCMAKE_TOOLCHAIN_FILE=${HOME}/sdk/android-ndk-27b/build/cmake/android.toolchain.cmake \
      -DANDROID_STL=c++_shared -DVVDEC_ENABLE_LINK_TIME_OPT=OFF -DANDROID_PLATFORM=android-21 \
      -DCMAKE_INSTALL_PREFIX=prefix ..

It did not work for FFmpeg configuration only, so I might need to add extra libs of libc++ or still if that persist problem exists, then I might have look something else...

Feel free to reply or ask question again to me. Thanks! :)

* Martin Eesmaa
MartinEesmaa commented 2 days ago

Thanks for posting this issue of my comment. :) By the way, the title is misspelled Adroid, correct first title word is Android.

K-os commented 2 days ago

Why did you explicitly set the ANDROID_STL ? Did the default not work? Otherwise the cmake command line looks Ok to me.

I see you are building mpv-android. We actually do have instructions for building that with VVdeC in our wiki: https://github.com/fraunhoferhhi/vvdec/wiki/How-to-use-VVdeC#build-mpv-android-with-vvc-support

MartinEesmaa commented 2 days ago

Why did you explicitly set the ANDROID_STL ? Did the default not work? Otherwise the cmake command line looks Ok to me.

Cause, I set ANDROID_STL for C++ shared creates shared library module, so whenever the user can disassembly apk file and replace latest vvdec shared library built of Android on lib folder and repack apk file using apktool. Also default without ANDROID_STL argument did not work too.

Last twenty-one lines of default without ANDROID_STL, but different log:

>>> referenced by sstream:901 (/home/martineesmaa/mpv-android-vvc/buildscripts/sdk/android-ndk-r27b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/sstream:901)
>>>               vvdecimpl.cpp.o:(vvdec::Exception& vvdec::Exception::operator<<<char [14]>(char const (&) [14])) in archive /home/martineesmaa/mpv-android-vvc/buildscripts/prefix/arm64/lib/libvvdec.a
>>> referenced by sstream:901 (/home/martineesmaa/mpv-android-vvc/buildscripts/sdk/android-ndk-r27b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/sstream:901)
>>>               vvdecimpl.cpp.o:(vvdec::Exception& vvdec::Exception::operator<<<char [14]>(char const (&) [14])) in archive /home/martineesmaa/mpv-android-vvc/buildscripts/prefix/arm64/lib/libvvdec.a
>>> referenced by sstream:901 (/home/martineesmaa/mpv-android-vvc/buildscripts/sdk/android-ndk-r27b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/sstream:901)
>>>               vvdecimpl.cpp.o:(vvdec::Exception& vvdec::Exception::operator<<<char [6]>(char const (&) [6])) in archive /home/martineesmaa/mpv-android-vvc/buildscripts/prefix/arm64/lib/libvvdec.a
>>> referenced 461 more times
>>> the vtable symbol may be undefined because the class is missing its key function (see https://lld.llvm.org/missingkeyfunction)

ld.lld: error: undefined symbol: VTT for std::__ndk1::basic_ostringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>
>>> referenced by ostream:216 (/home/martineesmaa/mpv-android-vvc/buildscripts/sdk/android-ndk-r27b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/ostream:216)
>>>               vvdecimpl.cpp.o:(vvdec::Exception& vvdec::Exception::operator<<<char [14]>(char const (&) [14])) in archive /home/martineesmaa/mpv-android-vvc/buildscripts/prefix/arm64/lib/libvvdec.a
>>> referenced by ostream:216 (/home/martineesmaa/mpv-android-vvc/buildscripts/sdk/android-ndk-r27b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/ostream:216)
>>>               vvdecimpl.cpp.o:(vvdec::Exception& vvdec::Exception::operator<<<char [14]>(char const (&) [14])) in archive /home/martineesmaa/mpv-android-vvc/buildscripts/prefix/arm64/lib/libvvdec.a
>>> referenced by ostream:216 (/home/martineesmaa/mpv-android-vvc/buildscripts/sdk/android-ndk-r27b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/ostream:216)
>>>               vvdecimpl.cpp.o:(vvdec::Exception& vvdec::Exception::operator<<<char [6]>(char const (&) [6])) in archive /home/martineesmaa/mpv-android-vvc/buildscripts/prefix/arm64/lib/libvvdec.a
>>> referenced 463 more times

Full log of compressed file: config.zip

I remember last time I compiled vvdec commit (c26979fac06cf0405da7c901b7826ed517444f95) with mpv-android-vvc was 17th June 2024.

EDIT: Even I tried to compile Linux of my custom mpv-build repo did not work for FFmpeg configuration due not found of libvvdec, but cross compiling Windows & Linux in another repo FFmpeg-Builds are fine without issues.

Feel free to reply me again. Thanks! :)

K-os commented 2 days ago

So, you are saying you want the user to be able to replace the vvdec library in the APK, but you are building libvvdec statically. You need to add -DBUILD_SHARED_LIBS=1 to build the shared library.

Otherwise, if you want to link FFmpeg statically against vvdec, you need to link FFmpeg directly against the correct c++ standard library. You can tell the configure script, that it has to link the private dependencies of libvvdec by passing --pkg-config-flags=--static. Unfortunately, this is only possible as a global option, so FFmpeg will be linked directly against the private dependencies of all other dependencies. To work around that, you can read the Libs.private from the correct libvvdec.pc and add these as --extra-ldflags