I have a cmake project that creates a shared library that uses FFMPEG from vcpkg, and installs the shared library along with FFMPEG .so (or .dll) files using the RUNTIME_DEPENDENCY_SET option. On Windows, this works fine. However, on Linux, the install step fails with the following error message because I have multiple versions of ffmpeg on my system:
CMake Error at build/cmake_install.cmake:100 (file):
file Multiple conflicting paths found for libavutil.so.56:
/home/wanglab/Programs/vcpkg/installed/x64-linux-dynamic/lib/libavutil.so.56
/home/wanglab/mambaforge3/envs/moose/lib/./libavutil.so.56
/home/wanglab/mambaforge3/envs/moose/lib/libavutil.so.56
The problem only seems to exist when I return a type defined in ffmpeg, but not for functions where I use ffmpeg functions and types internally. Additionally, if I define my functions that return ffmpeg types in the header using inline, I am able to install the ffmpeg libraries. So this function is okay:
void say_hello(std::string codec_name)
{
::AVCodec* codec = ::avcodec_find_encoder_by_name(codec_name.c_str());
std::cout << "Hello World" << std::endl;
std::cout << codec << std::endl;
}
but this function will produce the error unless i define it inline in the header file:
::AVDictionary* make_my_dict(const std::multimap<std::string, std::string> dict)
{
::AVDictionary* d = nullptr;
for (const auto& entry : dict) {
::av_dict_set(&d, entry.first.c_str(), entry.second.c_str(), 0);
}
return d;
}
I find ffmpeg during configuration like this in my CMakeLists.txt:
find_package(PkgConfig REQUIRED)
pkg_check_modules(FFMPEG REQUIRED IMPORTED_TARGET
libavcodec
libavformat
libavutil
libswscale
libswresample)
target_link_libraries(ffmpeg_test PRIVATE PkgConfig::FFMPEG)
and the error only comes during installation with these commands:
install(TARGETS ffmpeg_test RUNTIME_DEPENDENCY_SET appDeps)
install(RUNTIME_DEPENDENCY_SET appDeps)
So there are no issues if I don’t try to copy the .so libraries into the installation folder.
I have been unsuccessful at creating a post_include_regex to select the right ffmpeg libraries in the RUNTIME_DEPENDENCY_SET block. I am able to select the correct (vcpkg) ffmpeg in the configuration step, and my cmakecache appears to be accurate. I have read that these variables do not propagate to the install commands. On linux, is there a way to prevent cmake from finding conflicting paths when multiple c libraries are in the path during install? Is there a reason this doesn’t happen if the troublesome functions are defined in the header?
I am using CMake 3.23.1. Please let me know if you need additional information.