如何更正CMAKE错误:找不到包'opencv'

时间:2022-01-28 15:39:14

OK, I know that opencv linking has been discussed before, but I can't see an error and I don't understand the corrective action. I'm trying to link DBoW2 library, which requires opencv. I'm getting undefined reference errors.

好的,我知道opencv链接之前已经讨论过,但我看不到错误,我不理解纠正措施。我正在尝试链接DBoW2库,这需要opencv。我得到了未定义的引用错误。

$ mingw32-make
Linking CXX shared library ..\lib\libDBoW2.dll
CMakeFiles\DBoW2.dir/objects.a(FORB.cpp.obj):FORB.cpp:(.text+0x124): undefined reference to `cv::Mat::zeros(int, int, int)'
CMakeFiles\DBoW2.dir/objects.a(FORB.cpp.obj):FORB.cpp:(.text+0x1db): undefined reference to `cv::fastFree(void*)'
CMakeFiles\DBoW2.dir/objects.a(FORB.cpp.obj):FORB.cpp:(.text+0x394): undefined reference to `cv::Mat::deallocate()'
CMakeFiles\DBoW2.dir/objects.a(FORB.cpp.obj):FORB.cpp:(.text+0x46a): undefined reference to `cv::Mat::copyTo(cv::_OutputArray const&) const'
CMakeFiles\DBoW2.dir/objects.a(FORB.cpp.obj):FORB.cpp:(.text+0x503): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
CMakeFiles\DBoW2.dir/objects.a(FORB.cpp.obj):FORB.cpp:(.text+0x93f): undefined reference to `cv::Mat::create(int, int const*, int)'
collect2.exe: error: ld returned 1 exit status

Here's the CMakeLists.txt file

这是CMakeLists.txt文件

cmake_minimum_required(VERSION 2.8)
project(DBoW2)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  -Wall  -O3 -march=native ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall  -O3 -march=native")

set(HDRS_DBOW2
  DBoW2/BowVector.h
  DBoW2/FORB.h 
  DBoW2/FClass.h       
  DBoW2/FeatureVector.h
  DBoW2/ScoringObject.h   
  DBoW2/TemplatedVocabulary.h)
set(SRCS_DBOW2
  DBoW2/BowVector.cpp
  DBoW2/FORB.cpp      
  DBoW2/FeatureVector.cpp
  DBoW2/ScoringObject.cpp)

set(HDRS_DUTILS
  DUtils/Random.h
  DUtils/Timestamp.h)
set(SRCS_DUTILS
  DUtils/Random.cpp
  DUtils/Timestamp.cpp)

find_package(OpenCV REQUIRED)

set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

include_directories(${OpenCV_INCLUDE_DIRS})
add_library(DBoW2 SHARED ${SRCS_DBOW2} ${SRCS_DUTILS})
target_link_libraries(DBoW2 ${OpenCV_LIBS})

I'm using the gui interface, and the parameter OpenCV_DIR automatically sets to C:/OpenCV/minwg_64. Under that directory there is a directory lib containing library files like "libopencv_videostab300.dll.a"

我正在使用gui接口,参数OpenCV_DIR自动设置为C:/ OpenCV / minwg_64。在该目录下有一个包含库文件的目录lib,如“libopencv_videostab300.dll.a”

The CMakeCache.txt file contains the lines

CMakeCache.txt文件包含行

//Dependencies for the target
DBoW2_LIB_DEPENDS:STATIC=general;opencv_videostab;general;opencv_videoio;general;opencv_video;general;opencv_superres;general;opencv_stitching;general;opencv_shape;general;opencv_photo;general;opencv_objdetect;general;opencv_ml;general;opencv_imgproc;general;opencv_imgcodecs;general;opencv_highgui;general;opencv_hal;general;opencv_flann;general;opencv_features2d;general;opencv_core;general;opencv_calib3d;

From what I've read, the following lines should be sufficient, but I'm getting the linker errors.

根据我的阅读,以下几行应该足够了,但我收到了链接器错误。

find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(DBoW2 ${OpenCV_LIBS})

Edit 1:

In response to Chris Maes

回应Chris Maes

added the pkg check

添加了pkg检查

pkg_check_modules (OPENCV REQUIRED opencv)

Now the configure causes an error, which is progress, but I'm still at a loss. I must have an error in the opencv installation / build. I do have a second copy on an external drive, that was built recently (and easily) using something like cmake .. . But setting OpenCV_DIR to the external build produces the same error.

现在配置导致错误,这是进步,但我仍然处于亏损状态。我必须在opencv安装/构建中出错。我在外部驱动器上有第二个副本,它是最近(并且很容易)使用像cmake这样的东西构建的。但是将OpenCV_DIR设置为外部构建会产生相同的错误。

Found PkgConfig: C:/msys64/usr/bin/pkg-config.exe (found version "0.28") 
checking for module 'opencv'
  package 'opencv' not found

Edit 2:

Here are the settings that CMake automatically generates when I start a new cache and press generate twice (first time it only generates the make, sh).

以下是当我启动新缓存并按两次生成时CMake自动生成的设置(第一次只生成make,sh)。

CMAKE_BUILD_TYPE (BLANK)
CMAKE_GNUtoMS (UNCHECKED)
CMAKE_INSTALL_PREFIX C:/Program Files (x86)/DBoW2
CMAKE_MAKE_PROGRAM C:/msys64/mingw64/bin/mingw32-make.exe
CMAKE_SH C:/msys64/usr/bin/sh.exe
OpenCV_DIR C:/OpenCV/minwg_64

The directory C:/OpenCV/minwg_64 contains the opencv library built from mingw gcc 64, and cmake files including OpenCVConfig.cmake and directories bin and lib. I wonder if I need directory staticlib?

目录C:/ OpenCV / minwg_64包含从mingw gcc 64构建的opencv库,以及包括OpenCVConfig.cmake和目录bin和lib的cmake文件。我想知道我是否需要目录staticlib?

For windows environment, I have

对于Windows环境,我有

OPENCV_DIR = C:\OpenCV\minwg_64  (where built bin and lib are located)
OPENCV_VER = 300
PATH includes C:\OpenCV\minwg_64\bin

1 个解决方案

#1


0  

On linux I use pkg_check_modules plugin for cmake:

在linux上我使用ckgke的pkg_check_modules插件:

find_package( OpenCV REQUIRED )
find_package( PkgConfig REQUIRED )
pkg_check_modules (OPENCV REQUIRED opencv)
include_directories(/usr/include/opencv2)

target_link_libraries(DBoW2 ${OPENCV_LDFLAGS})

note: I don't remember why I used hardcoded /usr/include/opencv2, but I guess OPENCV_INCLUDE_DIRS wasn't any good when I tried. There might be a more clean way :)

注意:我不记得为什么我使用了硬编码/ usr / include / opencv2,但我想OPENCV_INCLUDE_DIRS在我尝试的时候没有任何好处。可能会有一个更干净的方式:)

#1


0  

On linux I use pkg_check_modules plugin for cmake:

在linux上我使用ckgke的pkg_check_modules插件:

find_package( OpenCV REQUIRED )
find_package( PkgConfig REQUIRED )
pkg_check_modules (OPENCV REQUIRED opencv)
include_directories(/usr/include/opencv2)

target_link_libraries(DBoW2 ${OPENCV_LDFLAGS})

note: I don't remember why I used hardcoded /usr/include/opencv2, but I guess OPENCV_INCLUDE_DIRS wasn't any good when I tried. There might be a more clean way :)

注意:我不记得为什么我使用了硬编码/ usr / include / opencv2,但我想OPENCV_INCLUDE_DIRS在我尝试的时候没有任何好处。可能会有一个更干净的方式:)