Задать вопрос
@Jonhef

Как исправить ошибку с OpenCV и C++?

Вот вывод:
[ 50%] Building CXX object CMakeFiles/opencv-project.dir/main.cpp.o
In file included from /Users/jonhef/opencv-project/main.cpp:1:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/opencv.hpp:52:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core.hpp:52:
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/cvdef.h:783:6: error: "OpenCV 4.x+ requires enabled C++11 support"
#    error "OpenCV 4.x+ requires enabled C++11 support"
     ^
In file included from /Users/jonhef/opencv-project/main.cpp:1:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/opencv.hpp:52:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core.hpp:53:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/base.hpp:58:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/cvstd.hpp:81:
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/cvstd_wrapper.hpp:45:12: error: unknown type name 'constexpr'
    static CV_CONSTEXPR std::true_type has_parenthesis_operator_check(typename std::is_same<typename std::decay<decltype(std::declval<T>().operator()(std::declval<Args>()...))>::type, Ret>::type*);
           ^
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/cvdef.h:804:24: note: expanded from macro 'CV_CONSTEXPR'
#  define CV_CONSTEXPR constexpr
                       ^
In file included from /Users/jonhef/opencv-project/main.cpp:1:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/opencv.hpp:52:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core.hpp:53:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/base.hpp:58:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/cvstd.hpp:81:
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/cvstd_wrapper.hpp:45:30: error: non-friend class member 'true_type' cannot have a qualified name
    static CV_CONSTEXPR std::true_type has_parenthesis_operator_check(typename std::is_same<typename std::decay<decltype(std::declval<T>().operator()(std::declval<Args>()...))>::type, Ret>::type*);
                        ~~~~~^
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/cvstd_wrapper.hpp:45:39: error: expected ';' at end of declaration list
    static CV_CONSTEXPR std::true_type has_parenthesis_operator_check(typename std::is_same<typename std::decay<decltype(std::declval<T>().operator()(std::declval<Args>()...))>::type, Ret>::type*);
                                      ^
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/cvstd_wrapper.hpp:47:31: error: unknown type name 'constexpr'
    template<typename> static CV_CONSTEXPR std::false_type has_parenthesis_operator_check(...);
                              ^
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/cvdef.h:804:24: note: expanded from macro 'CV_CONSTEXPR'
#  define CV_CONSTEXPR constexpr
                       ^
In file included from /Users/jonhef/opencv-project/main.cpp:1:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/opencv.hpp:52:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core.hpp:53:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/base.hpp:58:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/cvstd.hpp:81:
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/cvstd_wrapper.hpp:47:49: error: non-friend class member 'false_type' cannot have a qualified name
    template<typename> static CV_CONSTEXPR std::false_type has_parenthesis_operator_check(...);
                                           ~~~~~^
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/cvstd_wrapper.hpp:47:59: error: expected ';' at end of declaration list
    template<typename> static CV_CONSTEXPR std::false_type has_parenthesis_operator_check(...);
                                                          ^
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/cvstd_wrapper.hpp:78:17: error: expected ';' at end of declaration list
    inline Ptr() CV_NOEXCEPT : std::shared_ptr<T>() {}
                ^
In file included from /Users/jonhef/opencv-project/main.cpp:1:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/opencv.hpp:52:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core.hpp:56:
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/matx.hpp:143:15: error: no template named 'initializer_list' in namespace 'std'
    Matx(std::initializer_list<_Tp>); //!< initialize from an initializer list
         ~~~~~^
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/matx.hpp:397:14: error: no template named 'initializer_list' in namespace 'std'
    Vec(std::initializer_list<_Tp>);
        ~~~~~^
In file included from /Users/jonhef/opencv-project/main.cpp:1:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/opencv.hpp:52:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core.hpp:56:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/matx.hpp:542:
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/matx.inl.hpp:288:28: error: no template named 'initializer_list' in namespace 'std'
Matx<_Tp, m, n>::Matx(std::initializer_list<_Tp> list)
                      ~~~~~^
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/matx.inl.hpp:821:24: error: no template named 'initializer_list' in namespace 'std'
Vec<_Tp, cn>::Vec(std::initializer_list<_Tp> list)
                  ~~~~~^
In file included from /Users/jonhef/opencv-project/main.cpp:1:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/opencv.hpp:52:
In file included from /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core.hpp:57:
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/types.hpp:175:24: error: expected ';' at end of declaration list
    Point_(Point_&& pt) CV_NOEXCEPT = default;
                       ^
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/types.hpp:185:37: error: expected ';' at end of declaration list
    Point_& operator = (Point_&& pt) CV_NOEXCEPT = default;
                                    ^
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/types.hpp:264:26: error: expected ';' at end of declaration list
    Point3_(Point3_&& pt) CV_NOEXCEPT = default;
                         ^
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/types.hpp:271:39: error: expected ';' at end of declaration list
    Point3_& operator = (Point3_&& pt) CV_NOEXCEPT = default;
                                      ^
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/types.hpp:344:22: error: expected ';' at end of declaration list
    Size_(Size_&& sz) CV_NOEXCEPT = default;
                     ^
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/types.hpp:350:35: error: expected ';' at end of declaration list
    Size_& operator = (Size_&& sz) CV_NOEXCEPT = default;
                                  ^
/opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/opencv2/core/types.hpp:453:21: error: expected ';' at end of declaration list
    Rect_(Rect_&& r) CV_NOEXCEPT = default;
                    ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [CMakeFiles/opencv-project.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/opencv-project.dir/all] Error 2
make: *** [all] Error 2

CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
set(CMAKE_C_COMPILER /usr/bin/clang)
set(CMAKE_CXX_COMPILER /usr/bin/clang++)
project(opencv-project)

add_executable(opencv-project main.cpp)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(OpenCV_DIR /opt/homebrew/Cellar/opencv/4.10.0_12/include/opencv4/)

find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS

main.cpp:
#include <opencv2/opencv.hpp>

int main()
{
  cv::Mat img = cv::imread("test.png");
  cv::imshow("test", img);
  cv::waitKey(0);
  return 0;
}
  • Вопрос задан
  • 63 просмотра
Подписаться 1 Сложный Комментировать
Пригласить эксперта
Ответы на вопрос 1
Nipheris
@Nipheris Куратор тега C++
set(CMAKE_CXX_STANDARD 17)
Это нужно ставить ДО создания таргета, т.к. установка этой переменной выставляет дефолт для НОВЫХ таргетов.

А ещё лучше выставить проперти CXX_STANDARD с помощью set_target_properties.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы