Skip to content
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

Fix build using system ffmpeg when ffmpeg include dirs are empty and fix undefined reference to boost::log #1522

Merged
merged 2 commits into from
Jan 16, 2024

Conversation

nerijus
Copy link
Contributor

@nerijus nerijus commented Jan 16, 2024

No description provided.

@nerijus
Copy link
Contributor Author

nerijus commented Jan 16, 2024

Found 2 issues on CentOS 9. First one - I get link error with static boost:

[100%] Linking CXX executable casparcg
/usr/bin/ld: /usr/lib64/libboost_log_setup.a(init_from_settings.o): in function `boost::log::v2s_mt_posix::(anonymous namespace)::default_syslog_sink_factory<char>::create_sink(boost::log::v2s_mt_posix::basic_settings_section<char> const&)':
(.text[.text.group]+0x2cb9): undefined reference to `boost::log::v2s_mt_posix::sinks::syslog_backend::set_severity_mapper(boost::log::v2s_mt_posix::aux::light_function<boost::log::v2s_mt_posix::sinks::syslog::level (boost::log::v2s_mt_posix::record_view const&)> const&)'
/usr/bin/ld: (.text[.text.group]+0x30ae): undefined reference to `boost::log::v2s_mt_posix::sinks::syslog_backend::set_target_address(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned short)'
/usr/bin/ld: (.text[.text.group]+0x314e): undefined reference to `boost::log::v2s_mt_posix::sinks::syslog_backend::set_local_address(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned short)'
/usr/bin/ld: /usr/lib64/libboost_log_setup.a(init_from_settings.o): in function `boost::log::v2s_mt_posix::(anonymous namespace)::default_syslog_sink_factory<wchar_t>::create_sink(boost::log::v2s_mt_posix::basic_settings_section<wchar_t> const&)':
(.text[.text.group]+0x36a9): undefined reference to `boost::log::v2s_mt_posix::sinks::syslog_backend::set_severity_mapper(boost::log::v2s_mt_posix::aux::light_function<boost::log::v2s_mt_posix::sinks::syslog::level (boost::log::v2s_mt_posix::record_view const&)> const&)'
/usr/bin/ld: (.text[.text.group]+0x3ae8): undefined reference to `boost::log::v2s_mt_posix::sinks::syslog_backend::set_target_address(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned short)'
/usr/bin/ld: (.text[.text.group]+0x3bd0): undefined reference to `boost::log::v2s_mt_posix::sinks::syslog_backend::set_local_address(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned short)'
...

The issue is in FindBoost module in cmake. See boostorg/log#46 (comment) and https://gitlab.kitware.com/cmake/cmake/-/issues/20638.
Without this patch link command looks like this:

/usr/bin/c++ -O3 -DNDEBUG CMakeFiles/casparcg.dir/main.cpp.o CMakeFiles/casparcg.dir/server.cpp.o CMakeFiles/casparcg.dir/linux_specific.cpp.o -o casparcg   -L/opt/ffmpeg/lib  ... /usr/lib64/libboost_log.a /usr/lib64/libboost_locale.a /usr/lib64/libboost_regex.a /usr/lib64/libboost_date_time.a /usr/lib64/libboost_coroutine.a /usr/lib64/libboost_atomic.a /usr/lib64/libboost_log_setup.a ...

As you can see /usr/lib64/libboost_log_setup.a is included after /usr/lib64/libboost_log.a. With this PR the order is reversed and linking works correctly.

@nerijus
Copy link
Contributor Author

nerijus commented Jan 16, 2024

2nd issue is that pkgconf libavcodec --cflags does not output anything, probably because it should output -I/usr/include, but because /usr/include is included by default in current distros it is skipped. My /usr/lib64/pkgconfig/libavcodec.pc looks like this:

prefix=/usr
exec_prefix=${prefix}
libdir=/usr/lib64
includedir=/usr/include

Name: libavcodec
Description: FFmpeg codec library
Version: 59.37.100
...
Libs: -L${libdir}  -lavcodec
Libs.private: -lvpx -lm...
Cflags: -I${includedir}
$ pkgconf libavcodec --libs
-lavcodec 
$ pkgconf libavcodec --cflags
<empty line>

I modified FindFFmpeg.cmake like this:

diff --git a/src/CMakeModules/FindFFmpeg.cmake b/src/CMakeModules/FindFFmpeg.cmake
index a5560d808..a09cf6cdb 100644
--- a/src/CMakeModules/FindFFmpeg.cmake
+++ b/src/CMakeModules/FindFFmpeg.cmake
@@ -42,11 +42,13 @@ endif ()
 # Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present.
 #
 macro(set_component_found _component )
+  message(STATUS "${_component}_LIBRARIES=${${_component}_LIBRARIES}")
+  message(STATUS "${_component}_INCLUDE_DIRS=${${_component}_INCLUDE_DIRS}")
   if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS)
-    # message(STATUS "  - ${_component} found.")
+    message(STATUS "  - ${_component} found.")
     set(${_component}_FOUND TRUE)
   else ()
-    # message(STATUS "  - ${_component} not found.")
+    message(STATUS "  - ${_component} not found.")
   endif ()
 endmacro()

and got such output:

$ cmake -DUSE_SYSTEM_FFMPEG=ON ../src
-- AVCODEC_LIBRARIES=avcodec
-- AVCODEC_INCLUDE_DIRS=
--   - AVCODEC not found.
-- AVDEVICE_LIBRARIES=avdevice
-- AVDEVICE_INCLUDE_DIRS=
--   - AVDEVICE not found.
-- AVFORMAT_LIBRARIES=avformat
-- AVFORMAT_INCLUDE_DIRS=
--   - AVFORMAT not found.
-- AVUTIL_LIBRARIES=avutil
-- AVUTIL_INCLUDE_DIRS=
--   - AVUTIL not found.
-- POSTPROCESS_LIBRARIES=
-- POSTPROCESS_INCLUDE_DIRS=
--   - POSTPROCESS not found.
-- SWSCALE_LIBRARIES=swscale
-- SWSCALE_INCLUDE_DIRS=
--   - SWSCALE not found.
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find FFmpeg (missing: FFMPEG_INCLUDE_DIRS AVCODEC_INCLUDE_DIRS
  AVFORMAT_INCLUDE_DIRS AVUTIL_INCLUDE_DIRS AVDEVICE_INCLUDE_DIRS
  AVFILTER_INCLUDE_DIRS POSTPROC_INCLUDE_DIRS SWSCALE_INCLUDE_DIRS
  SWRESAMPLE_INCLUDE_DIRS)
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
  CMakeModules/FindFFmpeg.cmake:165 (find_package_handle_standard_args)
  CMakeModules/Bootstrap_Linux.cmake:45 (FIND_PACKAGE)
  CMakeLists.txt:36 (INCLUDE)

With my patch the build works.

@Julusian
Copy link
Member

thanks, both of these look sensible and don't break the ci builds so work fine on ubuntu still

perhaps I should add some more build tests based on different linux distros..

@Julusian Julusian merged commit fb253fd into CasparCG:master Jan 16, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants