0

I need to use vp8 encoder in my c++ project. I have compiled ffmpeg enabling libvpx library using

./configure --enable-libvpx

how do I add it to CmakeLists.txt. I got linking errors when I linked with

target_link_libraries(main "/path/to/libav")

Fureeish
  • 12,533
  • 4
  • 32
  • 62
  • 1
    "I got linking errors" - This description is quite vague. Please. add to the question post the **exact error message** you got. – Tsyvarev Jul 14 '22 at 12:47

1 Answers1

2

Using target_link_libraries

target_link_libraries expects a full path to a library file, so instead of calling

target_link_libraries(main PUB"/path/to/lib")

you should do

target_link_libraries(main "/path/to/lib/lib.so")

Using target_link_directories and target_link_libraries

You can explicitly provide directories, where the linker will look for your libraries. Combining this with target_link_libraries, you get

target_link_directories(main INTERFACE|PUBLIC|PRIVATE "/path/to/lib")
target_link_libraries(main lib)

Using pkg-config

FFmpeg generates pkg-config file, which is a handy solution to handle dependencies. CMake has a module, which supports pkg-config: FindPkgConfig

find_package(PkgConfig)

It provides a function pkg_check_modules, which searches for a .pc file for your library. Supposed you have a file lib.pc you should call

pkg_check_modules(LIB lib)

You can now link with a library by using specific variables set by pkg-config:

target_link_libraries(main ${LIB_LIBRARIES})
target_link_directories(main ${LIB_LIBRARY_DIRS})
target_include_directories(main ${LIB_INCLUDE_DIRS})

Don't forget to check whether your library was actually found:

if(NOT LIB_FOUND)
    # error message
endif()
Fureeish
  • 12,533
  • 4
  • 32
  • 62
raxonpc
  • 41
  • 2