无法在 CLion 中编译 OpenCV header 文件
Can't compile OpenCV header files in CLion
我最近在 Ubuntu 系统上安装了 OpenCV。我使用 here and here 中的说明来安装 OpenCV c++。
当我在文件中包含 opencv header 时:
#include <opencv2/opencv.hpp>
构建时出现以下错误:
note: ‘cv::Range’ declared here
589 | class CV_EXPORTS Range
| ^~~~~
In file included from /usr/local/include/opencv4/opencv2/core.hpp:59,
from /usr/local/include/opencv4/opencv2/core/core.hpp:48,
from /home/mo/CLionProjects/DisjointForest/main.cpp:4:
/usr/local/include/opencv4/opencv2/core/mat.hpp:1640:43: error: template argument 1 is invalid
1640 | Mat operator()(const std::vector<Range>& ranges) const;
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1640:43: error: template argument 2 is invalid
/usr/local/include/opencv4/opencv2/core/mat.hpp:1640:9: error: ‘Mat Mat::operator()(const int&) const’ cannot be overloaded with ‘Mat Mat::operator()(const int&) const’
1640 | Mat operator()(const std::vector<Range>& ranges) const;
| ^~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1630:9: note: previous declaration ‘Mat Mat::operator()(const int&) const’
1630 | Mat operator()( const Rect& roi ) const;
| ^~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1643:44: error: expected type-specifier
1643 | template<typename _Tp, int n> operator Vec<_Tp, n>() const;
| ^~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1644:51: error: expected type-specifier
1644 | template<typename _Tp, int m, int n> operator Matx<_Tp, m, n>() const;
| ^~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1850:38: error: ‘Vec’ does not name a type
1850 | template<int n> uchar* ptr(const Vec<int, n>& idx);
| ^~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1850:41: error: expected ‘,’ or ‘...’ before ‘<’ token
1850 | template<int n> uchar* ptr(const Vec<int, n>& idx);
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1852:44: error: ‘Vec’ does not name a type
1852 | template<int n> const uchar* ptr(const Vec<int, n>& idx) const;
| ^~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1852:47: error: expected ‘,’ or ‘...’ before ‘<’ token
1852 | template<int n> const uchar* ptr(const Vec<int, n>& idx) const;
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1877:50: error: ‘Vec’ does not name a type
1877 | template<typename _Tp, int n> _Tp* ptr(const Vec<int, n>& idx);
| ^~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1877:53: error: expected ‘,’ or ‘...’ before ‘<’ token
1877 | template<typename _Tp, int n> _Tp* ptr(const Vec<int, n>& idx);
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1879:56: error: ‘Vec’ does not name a type
1879 | template<typename _Tp, int n> const _Tp* ptr(const Vec<int, n>& idx) const;
| ^~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1879:59: error: expected ‘,’ or ‘...’ before ‘<’ token
1879 | template<typename _Tp, int n> const _Tp* ptr(const Vec<int, n>& idx) const;
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1950:49: error: ‘Vec’ does not name a type
1950 | template<typename _Tp, int n> _Tp& at(const Vec<int, n>& idx);
| ^~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1950:52: error: expected ‘,’ or ‘...’ before ‘<’ token
1950 | template<typename _Tp, int n> _Tp& at(const Vec<int, n>& idx);
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1952:55: error: ‘Vec’ does not name a type
1952 | template<typename _Tp, int n> const _Tp& at(const Vec<int, n>& idx) const;
| ^~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1952:58: error: expected ‘,’ or ‘...’ before ‘<’ token
1952 | template<typename _Tp, int n> const _Tp& at(const Vec<int, n>& idx) const;
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1958:36: error: ‘Point’ was not declared in this scope; did you mean ‘cv::Point’?
1958 | template<typename _Tp> _Tp& at(Point pt);
| ^~~~~
| cv::Point
In file included from /usr/local/include/opencv4/opencv2/core.hpp:58,
from /usr/local/include/opencv4/opencv2/core/core.hpp:48,
from /home/mo/CLionProjects/DisjointForest/main.cpp:4:
/usr/local/include/opencv4/opencv2/core/types.hpp:194:17: note: ‘cv::Point’ declared here
194 | typedef Point2i Point;
| ^~~~~
In file included from /usr/local/include/opencv4/opencv2/core.hpp:59,
from /usr/local/include/opencv4/opencv2/core/core.hpp:48,
from /home/mo/CLionProjects/DisjointForest/main.cpp:4:
/usr/local/include/opencv4/opencv2/core/mat.hpp:1958:45: error: data member ‘at’ cannot be a member template
1958 | template<typename _Tp> _Tp& at(Point pt);
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1963:42: error: ‘Point’ was not declared in this scope; did you mean ‘cv::Point’?
1963 | template<typename _Tp> const _Tp& at(Point pt) const;
| ^~~~~
| cv::Point
In file included from /usr/local/include/opencv4/opencv2/core.hpp:58,
from /usr/local/include/opencv4/opencv2/core/core.hpp:48,
from /home/mo/CLionProjects/DisjointForest/main.cpp:4:
/usr/local/include/opencv4/opencv2/core/types.hpp:194:17: note: ‘cv::Point’ declared here
194 | typedef Point2i Point;
| ^~~~~
In file included from /usr/local/include/opencv4/opencv2/core.hpp:59,
from /usr/local/include/opencv4/opencv2/core/core.hpp:48,
from /home/mo/CLionProjects/DisjointForest/main.cpp:4:
/usr/local/include/opencv4/opencv2/core/mat.hpp:1963:51: error: expected ‘;’ before ‘const’
1963 | template<typename _Tp> const _Tp& at(Point pt) const;
| ^~~~~~
| ;
/usr/local/include/opencv4/opencv2/core/mat.hpp:1963:57: error: data member ‘at’ cannot be a member template
1963 | template<typename _Tp> const _Tp& at(Point pt) const;
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:2001:28: error: ‘MatIterator_’ does not name a type
2001 | template<typename _Tp> MatIterator_<_Tp> begin();
| ^~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:2002:28: error: ‘MatConstIterator_’ does not name a type
2002 | template<typename _Tp> MatConstIterator_<_Tp> begin() const;
| ^~~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:2009:28: error: ‘MatIterator_’ does not name a type
2009 | template<typename _Tp> MatIterator_<_Tp> end();
| ^~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:2010:28: error: ‘MatConstIterator_’ does not name a type
2010 | template<typename _Tp> MatConstIterator_<_Tp> end() const;
| ^~~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:957:68: error: ‘Range’ has not been declared
957 | Mat(const Mat& m, const Range& rowRange, const Range& colRange=Range::all());
| ^~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:2181:22: error: expected nested-name-specifier before ‘DataType’
2181 | typedef typename DataType<_Tp>::channel_type channel_type;
| ^~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:2181:22: error: expected ‘;’ at end of member declaration
2181 | typedef typename DataType<_Tp>::channel_type channel_type;
| ^~~~~~~~
| ;
/usr/local/include/opencv4/opencv2/core/mat.hpp:2181:30: error: expected unqualified-id before ‘<’ token
2181 | typedef typename DataType<_Tp>::channel_type channel_type;
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:2182:13: error: ‘MatIterator_’ does not name a type
2182 | typedef MatIterator_<_Tp> iterator;
| ^~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:2183:13: error: ‘MatConstIterator_’ does not name a type
2183 | typedef MatConstIterator_<_Tp> const_iterator;
| ^~~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:2192:23: error: expected ‘)’ before ‘_size’
2192 | explicit Mat_(Size _size);
| ~ ^~~~~~
| )
/usr/local/include/opencv4/opencv2/core/mat.hpp:2194:14: error: expected ‘)’ before ‘_size’
2194 | Mat_(Size _size, const _Tp& value);
| ~ ^~~~~~
| )
/usr/local/include/opencv4/opencv2/core/mat.hpp:2208:31: error: ‘Range’ does not name a type
2208 | Mat_(const Mat_& m, const Range& rowRange, const Range& colRange=Range::all());
| ^~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:2208:54: error: ‘Range’ does not name a type
2208 | Mat_(const Mat_& m, const Range& rowRange, const Range& colRange=Range::all());
| ^~~~~
.....................
.....................
In file included from /usr/local/include/opencv4/opencv2/core.hpp:3294,
from /usr/local/include/opencv4/opencv2/core/core.hpp:48,
from /home/mo/CLionProjects/DisjointForest/main.cpp:4:
/usr/local/include/opencv4/opencv2/core/optim.hpp:296:26: error: ‘InputArray’ was not declared in this scope; did you mean ‘OutputArray’?
296 | CV_EXPORTS_W int solveLP(InputArray Func, InputArray Constr, OutputArray z);
| ^~~~~~~~~~
| OutputArray
/usr/local/include/opencv4/opencv2/core/optim.hpp:296:43: error: ‘InputArray’ was not declared in this scope; did you mean ‘OutputArray’?
296 | CV_EXPORTS_W int solveLP(InputArray Func, InputArray Constr, OutputArray z);
| ^~~~~~~~~~
| OutputArray
/usr/local/include/opencv4/opencv2/core/optim.hpp:296:74: error: expected primary-expression before ‘z’
296 | CV_EXPORTS_W int solveLP(InputArray Func, InputArray Constr, OutputArray z);
| ^
/usr/local/include/opencv4/opencv2/core/optim.hpp:296:75: error: expression list treated as compound expression in initializer [-fpermissive]
296 | CV_EXPORTS_W int solveLP(InputArray Func, InputArray Constr, OutputArray z);
| ^
make[3]: *** [CMakeFiles/DisjointForest.dir/build.make:63: CMakeFiles/DisjointForest.dir/main.cpp.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:76: CMakeFiles/DisjointForest.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/DisjointForest.dir/rule] Error 2
make: *** [Makefile:118: DisjointForest] Error 2
我不知道这个错误是什么意思。有人可以指导我如何修复此错误并开始使用 openCV 吗?
如果有帮助,这是我的 cmake 文件:
cmake_minimum_required(VERSION 3.16)
project(DisjointForest)
set(CMAKE_CXX_STANDARD 20)
find_package(OpenCV 4.3.0 REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(DisjointForest main.cpp LinkedListDisjointSet.cpp DisjointForest.cpp DisjointForest.h)
target_link_directories(DisjointForest PUBLIC ${OpenCV_LIBS})
好的,在对链接器和链接库进行了大量研究之后,我意识到了两个问题:
1) 将 c++ 20 更改为 c++ 17 编译头文件。也许这个库还不兼容 c++20。
2) 改变以上内容是不够的,因为我们还没有正确链接库。它仍然会给出未解决的错误。在我的 cmake 文件中,我需要将 target_link_directories()
替换为 target_link_libraries()
。这是我在按照问题中的链接中的说明进行操作时犯的一个愚蠢的错误。
我最近在 Ubuntu 系统上安装了 OpenCV。我使用 here and here 中的说明来安装 OpenCV c++。
当我在文件中包含 opencv header 时:
#include <opencv2/opencv.hpp>
构建时出现以下错误:
note: ‘cv::Range’ declared here
589 | class CV_EXPORTS Range
| ^~~~~
In file included from /usr/local/include/opencv4/opencv2/core.hpp:59,
from /usr/local/include/opencv4/opencv2/core/core.hpp:48,
from /home/mo/CLionProjects/DisjointForest/main.cpp:4:
/usr/local/include/opencv4/opencv2/core/mat.hpp:1640:43: error: template argument 1 is invalid
1640 | Mat operator()(const std::vector<Range>& ranges) const;
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1640:43: error: template argument 2 is invalid
/usr/local/include/opencv4/opencv2/core/mat.hpp:1640:9: error: ‘Mat Mat::operator()(const int&) const’ cannot be overloaded with ‘Mat Mat::operator()(const int&) const’
1640 | Mat operator()(const std::vector<Range>& ranges) const;
| ^~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1630:9: note: previous declaration ‘Mat Mat::operator()(const int&) const’
1630 | Mat operator()( const Rect& roi ) const;
| ^~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1643:44: error: expected type-specifier
1643 | template<typename _Tp, int n> operator Vec<_Tp, n>() const;
| ^~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1644:51: error: expected type-specifier
1644 | template<typename _Tp, int m, int n> operator Matx<_Tp, m, n>() const;
| ^~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1850:38: error: ‘Vec’ does not name a type
1850 | template<int n> uchar* ptr(const Vec<int, n>& idx);
| ^~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1850:41: error: expected ‘,’ or ‘...’ before ‘<’ token
1850 | template<int n> uchar* ptr(const Vec<int, n>& idx);
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1852:44: error: ‘Vec’ does not name a type
1852 | template<int n> const uchar* ptr(const Vec<int, n>& idx) const;
| ^~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1852:47: error: expected ‘,’ or ‘...’ before ‘<’ token
1852 | template<int n> const uchar* ptr(const Vec<int, n>& idx) const;
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1877:50: error: ‘Vec’ does not name a type
1877 | template<typename _Tp, int n> _Tp* ptr(const Vec<int, n>& idx);
| ^~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1877:53: error: expected ‘,’ or ‘...’ before ‘<’ token
1877 | template<typename _Tp, int n> _Tp* ptr(const Vec<int, n>& idx);
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1879:56: error: ‘Vec’ does not name a type
1879 | template<typename _Tp, int n> const _Tp* ptr(const Vec<int, n>& idx) const;
| ^~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1879:59: error: expected ‘,’ or ‘...’ before ‘<’ token
1879 | template<typename _Tp, int n> const _Tp* ptr(const Vec<int, n>& idx) const;
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1950:49: error: ‘Vec’ does not name a type
1950 | template<typename _Tp, int n> _Tp& at(const Vec<int, n>& idx);
| ^~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1950:52: error: expected ‘,’ or ‘...’ before ‘<’ token
1950 | template<typename _Tp, int n> _Tp& at(const Vec<int, n>& idx);
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1952:55: error: ‘Vec’ does not name a type
1952 | template<typename _Tp, int n> const _Tp& at(const Vec<int, n>& idx) const;
| ^~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1952:58: error: expected ‘,’ or ‘...’ before ‘<’ token
1952 | template<typename _Tp, int n> const _Tp& at(const Vec<int, n>& idx) const;
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1958:36: error: ‘Point’ was not declared in this scope; did you mean ‘cv::Point’?
1958 | template<typename _Tp> _Tp& at(Point pt);
| ^~~~~
| cv::Point
In file included from /usr/local/include/opencv4/opencv2/core.hpp:58,
from /usr/local/include/opencv4/opencv2/core/core.hpp:48,
from /home/mo/CLionProjects/DisjointForest/main.cpp:4:
/usr/local/include/opencv4/opencv2/core/types.hpp:194:17: note: ‘cv::Point’ declared here
194 | typedef Point2i Point;
| ^~~~~
In file included from /usr/local/include/opencv4/opencv2/core.hpp:59,
from /usr/local/include/opencv4/opencv2/core/core.hpp:48,
from /home/mo/CLionProjects/DisjointForest/main.cpp:4:
/usr/local/include/opencv4/opencv2/core/mat.hpp:1958:45: error: data member ‘at’ cannot be a member template
1958 | template<typename _Tp> _Tp& at(Point pt);
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1963:42: error: ‘Point’ was not declared in this scope; did you mean ‘cv::Point’?
1963 | template<typename _Tp> const _Tp& at(Point pt) const;
| ^~~~~
| cv::Point
In file included from /usr/local/include/opencv4/opencv2/core.hpp:58,
from /usr/local/include/opencv4/opencv2/core/core.hpp:48,
from /home/mo/CLionProjects/DisjointForest/main.cpp:4:
/usr/local/include/opencv4/opencv2/core/types.hpp:194:17: note: ‘cv::Point’ declared here
194 | typedef Point2i Point;
| ^~~~~
In file included from /usr/local/include/opencv4/opencv2/core.hpp:59,
from /usr/local/include/opencv4/opencv2/core/core.hpp:48,
from /home/mo/CLionProjects/DisjointForest/main.cpp:4:
/usr/local/include/opencv4/opencv2/core/mat.hpp:1963:51: error: expected ‘;’ before ‘const’
1963 | template<typename _Tp> const _Tp& at(Point pt) const;
| ^~~~~~
| ;
/usr/local/include/opencv4/opencv2/core/mat.hpp:1963:57: error: data member ‘at’ cannot be a member template
1963 | template<typename _Tp> const _Tp& at(Point pt) const;
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:2001:28: error: ‘MatIterator_’ does not name a type
2001 | template<typename _Tp> MatIterator_<_Tp> begin();
| ^~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:2002:28: error: ‘MatConstIterator_’ does not name a type
2002 | template<typename _Tp> MatConstIterator_<_Tp> begin() const;
| ^~~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:2009:28: error: ‘MatIterator_’ does not name a type
2009 | template<typename _Tp> MatIterator_<_Tp> end();
| ^~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:2010:28: error: ‘MatConstIterator_’ does not name a type
2010 | template<typename _Tp> MatConstIterator_<_Tp> end() const;
| ^~~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:957:68: error: ‘Range’ has not been declared
957 | Mat(const Mat& m, const Range& rowRange, const Range& colRange=Range::all());
| ^~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:2181:22: error: expected nested-name-specifier before ‘DataType’
2181 | typedef typename DataType<_Tp>::channel_type channel_type;
| ^~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:2181:22: error: expected ‘;’ at end of member declaration
2181 | typedef typename DataType<_Tp>::channel_type channel_type;
| ^~~~~~~~
| ;
/usr/local/include/opencv4/opencv2/core/mat.hpp:2181:30: error: expected unqualified-id before ‘<’ token
2181 | typedef typename DataType<_Tp>::channel_type channel_type;
| ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:2182:13: error: ‘MatIterator_’ does not name a type
2182 | typedef MatIterator_<_Tp> iterator;
| ^~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:2183:13: error: ‘MatConstIterator_’ does not name a type
2183 | typedef MatConstIterator_<_Tp> const_iterator;
| ^~~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:2192:23: error: expected ‘)’ before ‘_size’
2192 | explicit Mat_(Size _size);
| ~ ^~~~~~
| )
/usr/local/include/opencv4/opencv2/core/mat.hpp:2194:14: error: expected ‘)’ before ‘_size’
2194 | Mat_(Size _size, const _Tp& value);
| ~ ^~~~~~
| )
/usr/local/include/opencv4/opencv2/core/mat.hpp:2208:31: error: ‘Range’ does not name a type
2208 | Mat_(const Mat_& m, const Range& rowRange, const Range& colRange=Range::all());
| ^~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:2208:54: error: ‘Range’ does not name a type
2208 | Mat_(const Mat_& m, const Range& rowRange, const Range& colRange=Range::all());
| ^~~~~
.....................
.....................
In file included from /usr/local/include/opencv4/opencv2/core.hpp:3294,
from /usr/local/include/opencv4/opencv2/core/core.hpp:48,
from /home/mo/CLionProjects/DisjointForest/main.cpp:4:
/usr/local/include/opencv4/opencv2/core/optim.hpp:296:26: error: ‘InputArray’ was not declared in this scope; did you mean ‘OutputArray’?
296 | CV_EXPORTS_W int solveLP(InputArray Func, InputArray Constr, OutputArray z);
| ^~~~~~~~~~
| OutputArray
/usr/local/include/opencv4/opencv2/core/optim.hpp:296:43: error: ‘InputArray’ was not declared in this scope; did you mean ‘OutputArray’?
296 | CV_EXPORTS_W int solveLP(InputArray Func, InputArray Constr, OutputArray z);
| ^~~~~~~~~~
| OutputArray
/usr/local/include/opencv4/opencv2/core/optim.hpp:296:74: error: expected primary-expression before ‘z’
296 | CV_EXPORTS_W int solveLP(InputArray Func, InputArray Constr, OutputArray z);
| ^
/usr/local/include/opencv4/opencv2/core/optim.hpp:296:75: error: expression list treated as compound expression in initializer [-fpermissive]
296 | CV_EXPORTS_W int solveLP(InputArray Func, InputArray Constr, OutputArray z);
| ^
make[3]: *** [CMakeFiles/DisjointForest.dir/build.make:63: CMakeFiles/DisjointForest.dir/main.cpp.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:76: CMakeFiles/DisjointForest.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/DisjointForest.dir/rule] Error 2
make: *** [Makefile:118: DisjointForest] Error 2
我不知道这个错误是什么意思。有人可以指导我如何修复此错误并开始使用 openCV 吗?
如果有帮助,这是我的 cmake 文件:
cmake_minimum_required(VERSION 3.16)
project(DisjointForest)
set(CMAKE_CXX_STANDARD 20)
find_package(OpenCV 4.3.0 REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(DisjointForest main.cpp LinkedListDisjointSet.cpp DisjointForest.cpp DisjointForest.h)
target_link_directories(DisjointForest PUBLIC ${OpenCV_LIBS})
好的,在对链接器和链接库进行了大量研究之后,我意识到了两个问题:
1) 将 c++ 20 更改为 c++ 17 编译头文件。也许这个库还不兼容 c++20。
2) 改变以上内容是不够的,因为我们还没有正确链接库。它仍然会给出未解决的错误。在我的 cmake 文件中,我需要将 target_link_directories()
替换为 target_link_libraries()
。这是我在按照问题中的链接中的说明进行操作时犯的一个愚蠢的错误。