* target_link_libraries * should handle it for you. If you are not already using the FindOpenCV.cmake module to find libraries that are probably the problem, and you should try the following. To do this, first get the FindOpenCV.cmake file and put it in your project path (usually {project_dir} / cmake / Modules) and add the following line to your CMakeLists.txt:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
This will allow CMake to use the custom FindOpenCV.cmake method when resolving libraries. Then add:
FIND_PACKAGE( OpenCV REQUIRED ) TARGET_LINK_LIBRARIES( PROJECT_NAME_HERE ${OpenCV_LIBS} )
Although you do not need to set linker flags with CMAKE_SHARED_LINKER_FLAGS .
source share