我使用this链接来安装OpenCV。
什么有效:
1.OpenCV适用于python(从终端运行)。
2.我可以在单个C ++程序中导入opencv库。
什么行不通:
当代码遍布多个时,您需要使用CMake构建它。
这是我的CmakeLists.txt:
1.cmake_minimum_required(VERSION 3.9)
2.project(Image_processing)
3.set(CMAKE_CXX_STANDARD 14)
4.find_package(OpenCV REQUIRED)
5.include_directories(/home/user/opencv/build)
6.add_executable(main main.cpp)
7.target_link_libraries(project_name ${OpenCV_LIBS})
错误(可以通过在上面的CMake文件中注释第4,5和7行来重新生成它们):
undefined reference
到OpenCV的功能。
CMake Error at CMakeLists.txt:7 (target_link_libraries):
Cannot specify link libraries for target "Image_processing" which is not
built by this project.
纠正它:
cmake_minimum_required(VERSION 3.5)
project(Image_processing)
set(CMAKE_CXX_STANDARD 14)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(main main.cpp)
target_link_libraries(main ${OpenCV_LIBS})
在CMakeLists.txt
中,exe-name与target-link-name不匹配。我修改了这条线,然后它可以在我的电脑上运行。
CMakeLists.txt
的OpenCV Project
:
cmake_minimum_required(VERSION 3.5)
project(Image_processing)
set(CMAKE_CXX_STANDARD 14)
find_package(OpenCV REQUIRED)
#include_directories(/home/user/opencv/build)
add_executable(Image_processing main.cpp)
target_link_libraries(Image_processing ${OpenCV_LIBS})