将OpenCv与CLion一起使用

时间:2016-04-13 07:02:49

标签: c++ opencv clion

嘿我试图在基本操作系统上使用OpenCV Lib(基于Ubuntu)。

我遵循了本教程:

https://www.youtube.com/watch?v=i1K9rXiei9I

我将这些行添加到CmakeList.txt:

find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(myOpenCVTest ${OpenCV_LIBS})

但是当我构建项目时,它会失败并出现一些错误:

/usr/bin/ld: cannot find -lopencv_core
...

任何人都可以帮助我吗?

3 个答案:

答案 0 :(得分:15)

我解决了这个问题。

首先,我删除了所有旧的OpenCV文件和安装。

之后我按照guide来安装OpenCV和所有必需的软件包。

现在一切都在使用这个CmakeList.txt:

cmake_minimum_required(VERSION 2.8.4)
project(OpenCVTest)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

find_package( OpenCV REQUIRED )
set(SOURCE_FILES main.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries( ${PROJECT_NAME} ${OpenCV_LIBS} )

答案 1 :(得分:0)

我必须在cmake文件中强制声明OpenCV_FOUND 1,整个文件看起来像:

cmake_minimum_required(VERSION 3.3)
project(testing)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(OpenCV_FOUND 1)
find_package( OpenCV REQUIRED )

set(SOURCE_FILES main.cpp)

add_executable(testing ${SOURCE_FILES})

target_link_libraries(testing ${OpenCV_LIBS})

答案 2 :(得分:0)

(在我们在评论部分聊天之后)

我不确定您用于安装的视频是什么,但假设您使用了基于cmake的安装,则通常会运行make,然后sudo make install将所有内容复制到正确的位置

或者您可以添加link_directories(home/Projects/opencv/opencv-3/build/lib/)include_directories((home/Projects/opencv/opencv-3/include/)到您的CMakeLists.txt