title: How do I properly link ffmpeg using CMake in my Flutter plugin on Linux?
body: <p>I've written a Flutter plugin for Linux that uses <code>ffmpeg</code> and I'm having trouble building my example app that uses the plugin. I keep getting errors that there are no matching calls to several <code>ffmpeg</code> functions, which I can actually click into and see. Why is this happening and what can I do to fix it?</p>
  <p>Here is my plugin's <code>CMakeLists.txt</code>:</p>
  <pre><code>cmake_minimum_required(VERSION 3.10)
  set(PROJECT_NAME &quot;thumblr_linux&quot;)
  project(${PROJECT_NAME} LANGUAGES CXX)
  
  # This value is used when generating builds using this plugin, so it must
  # not be changed
  set(PLUGIN_NAME &quot;thumblr_linux_plugin&quot;)
  
  add_subdirectory(FFmpeg)
  
  add_library(${PLUGIN_NAME} SHARED
    &quot;thumblr_linux_plugin.cc&quot;
  )
  apply_standard_settings(${PLUGIN_NAME})
  set_target_properties(${PLUGIN_NAME} PROPERTIES
    CXX_VISIBILITY_PRESET hidden)
  target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
  target_include_directories(${PLUGIN_NAME} INTERFACE
    &quot;${CMAKE_CURRENT_SOURCE_DIR}/include&quot;)
  target_link_libraries(${PLUGIN_NAME} PRIVATE flutter)
  target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK FFmpgeg)
  
  # List of absolute paths to libraries that should be bundled with the plugin
  set(thumblr_linux_bundled_libraries
    &quot;&quot;
    PARENT_SCOPE
  )
  </code></pre>
  <p>and here is my <code>FFmpeg/CMakeLists.txt</code>:</p>
  <pre><code>cmake_minimum_required(VERSION 3.14)
  project(FFmpeg)
  
  find_package(PkgConfig REQUIRED)
  pkg_check_modules(AVCODEC     REQUIRED IMPORTED_TARGET libavcodec)
  pkg_check_modules(AVFORMAT    REQUIRED IMPORTED_TARGET libavformat)
  pkg_check_modules(AVFILTER    REQUIRED IMPORTED_TARGET libavfilter)
  pkg_check_modules(AVDEVICE    REQUIRED IMPORTED_TARGET libavdevice)
  pkg_check_modules(AVUTIL      REQUIRED IMPORTED_TARGET libavutil)
  pkg_check_modules(SWRESAMPLE  REQUIRED IMPORTED_TARGET libswresample)
  pkg_check_modules(SWSCALE     REQUIRED IMPORTED_TARGET libswscale)
  
  add_library(FFmpeg INTERFACE IMPORTED GLOBAL)
  
  target_link_libraries(FFmpeg INTERFACE
      PkgConfig::AVCODEC
      PkgConfig::AVFORMAT
      PkgConfig::AVFILTER
      PkgConfig::AVDEVICE
      PkgConfig::AVUTIL
      PkgConfig::SWRESAMPLE
      PkgConfig::SWSCALE
  )
  </code></pre>
  <p>and here are the error messages I get when building:</p>
  <pre><code>/home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:80:9: error: no matching function for call to 'avformat_open_input'
  /home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:84:9: error: no matching function for call to 'avformat_find_stream_info'
  /home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:88:5: error: no matching function for call to 'av_dump_format'
  /home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:102:61: error: assigning to 'AVCodecContext *' from incompatible type 'AVCodecParameters *'
  /home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:111:9: error: use of undeclared identifier 'avcodec_open'
  /home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:119:14: error: use of undeclared identifier 'avcodec_alloc_frame'
  /home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:122:17: error: use of undeclared identifier 'avcodec_alloc_frame'
  /home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:127:16: error: no matching function for call to 'atk_image_get_image_size'
  /home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:133:5: error: use of undeclared identifier 'av_image_fill_arrays'
  /home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:144:9: error: use of undeclared identifier 'avcodec_decode_video'
  /home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:179:15: error: unused variable 'ret' [-Werror,-Wunused-variable]
  /home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:211:5: error: no matching function for call to 'avformat_close_input'
  </code></pre>
  <p>the C++ code for the plugin itself can be found here: <a href="https://github.com/GroovinChip/thumblr/blob/main/thumblr_linux/linux/thumblr_linux_plugin.cc" rel="nofollow noreferrer">https://github.com/GroovinChip/thumblr/blob/main/thumblr_linux/linux/thumblr_linux_plugin.cc</a></p>