Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix FFmpeg configuration issue for adding library privates of gcc and clang in meson build file #1178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MartinEesmaa
Copy link

This will add libraries_private in libvmaf/src/meson.build to fix FFmpeg configuration issue.
I checked with FFmpeg configuration after -lstdc++ is added to libs.private in pkgconfig with ninja install and works well.

  • Martin Eesmaa

@kylophone
Copy link
Collaborator

More context is needed. Can you please describe the "FFmpeg configuration issue"?

@MartinEesmaa
Copy link
Author

Hi, @kylophone! I can describe about FFmpeg configuration issue.

When I finished compiling libvmaf and installed my prefix folder, then I head to FFmpeg to type command example like ./configure --enable-libvmaf --enable-static --extra-ldexeflags=-static --pkg-config-flags=-static --disable-w32threads and then FFmpeg doesn't recognize libvmaf means not found using pkg-config, so here's the error message and ffbuild config log of five last lines:

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../lib\libvmaf.a(svm.cpp.obj):svm.cpp:(.rdata$.refptr._ZNSt13runtime_errorD1Ev[.refptr._ZNSt13runtime_errorD1Ev]+0x0): undefined reference to `std::runtime_error::~runtime_error()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../lib\libvmaf.a(svm.cpp.obj):svm.cpp:(.rdata$.refptr._ZTVSt15basic_streambufIcSt11char_traitsIcEE[.refptr._ZTVSt15basic_streambufIcSt11char_traitsIcEE]+0x0): undefined reference to `vtable for std::basic_streambuf<char, std::char_traits<char> >'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../lib\libvmaf.a(svm.cpp.obj):svm.cpp:(.rdata$.refptr._ZTVNSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEEE[.refptr._ZTVNSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEEE]+0x0): undefined reference to `vtable for std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >'
collect2.exe: error: ld returned 1 exit status
ERROR: libvmaf >= 2.0.0 not found using pkg-config

The solution is I added -lstc++ in libvmaf/src/meson.build to fix FFmpeg configuration problem, so the FFmpeg can detect libvmaf operation well using additional command of -lstdc++, otherwise without -lstdc++ will fail.

Some peoples were having issue to compile FFmpeg with libvmaf static library, the issue is there:
#788

If you have any question or issues, please feel reply to me.
Thank you! :)

  • Martin Eesmaa

@1480c1
Copy link
Contributor

1480c1 commented Apr 4, 2023

A note of two things:

  1. Another possible solution, as mentioned in the issue, is to use the c++ compiler as the linker so that the appropriate standard c++ library gets linked, so --ld=g++ or clang++, but that's impossible to express from pkg config as far as I know.
  2. Adding -lstdc++ to the pkg config file could be wrong in the case that the user of the library compiled it against llvm's libc++ rather than libstdc++ https://libcxx.llvm.org/UsingLibcxx.html. I am not sure of the top of my head what would be the best way to detect which libc to use other than perhaps detecting -lc++ or -stdlib=libc++ from ldflags.

@MartinEesmaa
Copy link
Author

MartinEesmaa commented Apr 4, 2023

@1480c1, yeah you're probably right. I just tried with libc++ command in my GCC compiler and won't work. libc++ is the only can work for clang compiler and the gcc is libstdc++. I was wondering, if we can detect two compilers of GCC and Clang in meson.build, let's just say...

If compiler is GCC, it should go -lstdc++ with pre-pkgconfig. If compiler is clang, it should go -lc++ with pre-pkgconfig.
Maybe this can help a little bit?

  • Martin Eesmaa

@1480c1
Copy link
Contributor

1480c1 commented Apr 4, 2023

@1480c1, yeah you're probably right. I just tried with libc++ command in my GCC compiler and won't work. libc++ is the only can work for clang compiler and the gcc is libstdc++. I was wondering, if we can detect two compilers of GCC and Clang in meson.build, let's just say...

If compiler is GCC, it should go -lstdc++ with pre-pkgconfig. If compiler is clang, it should go -lc++ with pre-pkgconfig.

  • Martin Eesmaa

It is technically possible to use libc++ and g++ as noted in llvm's page

g++ -nostdinc++ -nodefaultlibs \
    -isystem <install>/include/c++/v1 \
    -L <install>/lib \
    -Wl,-rpath,<install>/lib \
    -lc++ -lc++abi -lm -lc -lgcc_s -lgcc \
    test.cpp

But it looks impossibly hard, so I think at least g++ == libstdc++ is a good assumption to start with.
However, I don't think clang++ == libc++ is a good one as on linux systems and on windows with mingw-w64, it uses libstdc++ by default.

You could try checking if the cxx_link_args variable contains the strings I mentioned. That's the best I got for now until I wake up in the morning.

@MartinEesmaa
Copy link
Author

Please check my new commit.

Thank you. :)

  • Martin Eesmaa

This will add libraries_private in libvmaf/src/meson.build to fix FFmpeg configuration issue.
@MartinEesmaa MartinEesmaa changed the title Fix FFmpeg configuration issue for adding -lstdc++ in meson build file Fix FFmpeg configuration issue for adding library privates of gcc and clang in meson build file Jun 7, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants