undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)‘

编译报错:

undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'

解决办法:
CMakeLists.txt中加入

find_package(OpenCV 3 QUIET)
target_link_libraries(program_name ${OpenCV_LIBS})

OpenCV 3 是安装OpenCV的版本号,如果装的4.*就写OpenCV 4
program_name是可执行程序名,即add_executable(program_name, code_file)中的program_name

你可能感兴趣的:(C++,opencv)