【发布时间】:2019-12-23 07:49:47
【问题描述】:
我想在我的项目文件夹中使用 opencv,因为我的其他同事并非都在同一个平台(Linux、Windows)上工作。因此,为了更容易克隆和编译项目,我只想制作一个克隆 git 并启动编译以便能够在项目上工作。 (不使用任何环境变量,完全独立)
与其他库 (glfw) 一样,我只是在我的依赖项文件夹中添加了解压缩的文件夹。然后我添加了 add_subdirectory 和 target_link_libraries 语句。
然后我得到一个我无法解决的小错误。
下面是关于我的项目的信息
1.项目文件夹结构
project
│ README.md
| CMakeLists.txt (my CMakeLists project)
└───dependencies
│ └───opencv-4.1.2
│ │ CMakeLists.txt (the original opencv CMakeLists (untouched))
│ │ ...
└───src
│ main.cpp
2。我的 CMakeLists 内容
cmake_minimum_required(VERSION 3.15)
project(OpTests)
set(CMAKE_CXX_STANDARD 17)
add_subdirectory(dependencies/opencv-4.1.2)
add_executable(OpTests src/main.cpp)
target_link_libraries(OpTests opencv_core opencv_highgui opencv_imgproc opencv_videoio)
3。 main.cpp 内容
#include <iostream>
#include <opencv2/opencv.hpp>
int main() {
std::cout << CV_VERSION << std::endl;
cv::Mat M(2,2, CV_8UC3, cv::Scalar(0,0,255));
std::cout << "M = " << std::endl << " " << M << std::endl << std::endl;
std::cout << "Hello, World!" << std::endl;
return 0;
}
4.错误
°
°
°
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jeremy/CLionProjects/OpTests/cmake-build-debug
[ 3%] Built target ittnotify
[ 9%] Built target ippiw
[ 18%] Built target libjasper
[ 45%] Built target libwebp
[ 69%] Built target opencv_core
[ 90%] Built target opencv_imgproc
[ 93%] Built target opencv_imgcodecs
[ 96%] Built target opencv_videoio
[100%] Built target opencv_highgui
Scanning dependencies of target OpTests
[100%] Linking CXX executable bin/OpTests
CMakeFiles/OpTests.dir/src/main.cpp.o: In function `cv::String::~String()':
/usr/include/opencv2/core/cvstd.hpp:664: undefined reference to `cv::String::deallocate()'
CMakeFiles/OpTests.dir/src/main.cpp.o: In function `cv::String::operator=(cv::String const&)':
/usr/include/opencv2/core/cvstd.hpp:672: undefined reference to `cv::String::deallocate()'
collect2: error: ld returned 1 exit status
CMakeFiles/OpTests.dir/build.make:88: recipe for target 'bin/OpTests' failed
make[3]: *** [bin/OpTests] Error 1
CMakeFiles/Makefile2:81: recipe for target 'CMakeFiles/OpTests.dir/all' failed
make[2]: *** [CMakeFiles/OpTests.dir/all] Error 2
CMakeFiles/Makefile2:88: recipe for target 'CMakeFiles/OpTests.dir/rule' failed
make[1]: *** [CMakeFiles/OpTests.dir/rule] Error 2
Makefile:186: recipe for target 'OpTests' failed
make: *** [OpTests] Error 2
所以 3 个问题:
我做错了什么? 是否可以在没有 100 行 CMakeLists 的情况下简单地修复它?
这是一种不好的做法吗?
提前谢谢你
美好的一天
【问题讨论】:
-
闻起来像您的系统 OpenCV 标头 (
/usr/include/opencv2/core/cvstd.hpp) 和您构建的 OpenCV 的 不兼容性。 -
然而,这些是克隆文件的标题。不过,感谢您的研究建议。