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()