I need to install opencv from source, because I want to use opencv package for Rust and have tried many ways, how to do it. I was even able to install opencv with make, however it didn’t work with Rust, so I removed it and hoped to install it again, and of course It doesn’t want to install. It breaks at:
make -j$(nproc)
The error(I will link part of the error, but most of these are the same) is mostly connected to c++14:
usr/include/c++/14/limits:1995:1: note: previous definition of ‘struct std::numeric_limits<__float128>’
1995 | __glibcxx_float_n(128)
| ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/chrono.h: In instantiation of ‘constexpr std::chrono::__enable_if_is_duration<_ToDur> std::chrono::duration_cast(const duration<_Rep, _Period>&) [with _ToDur = duration<long int>; _Rep = long int; _Period = std::ratio<1, 1000000000>; __enable_if_is_duration<_ToDur> = duration<long int>]’:
/usr/include/c++/14/bits/chrono.h:1247:7: required from here
/usr/include/c++/14/bits/chrono.h:286:17: error: no type named ‘type’ in ‘struct common_type<long int, long int, long int>’
286 | using __cr = typename common_type<__to_rep, _Rep, intmax_t>::type;
| ^~~~
/usr/include/c++/14/bits/chrono.h:287:17: error: no type named ‘type’ in ‘struct common_type<long int, long int, long int>’
287 | using __dc = __duration_cast_impl<_ToDur, __cf, __cr,
| ^~~~
[ 3%] Linking C static library ../lib/libippiw.a
/usr/include/c++/14/bits/unique_ptr.h: In instantiation of ‘std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = google::protobuf::MessageLite; _Dp = std::default_delete<google::protobuf::MessageLite>]’:
/home/wiktor/opencv_build/opencv/3rdparty/protobuf/src/google/protobuf/generated_message_util.cc:748:45: required from here
/usr/include/c++/14/bits/unique_ptr.h:394:63: error: incomplete type ‘__is_invocable<std::default_delete<google::protobuf::MessageLite>&, google::protobuf::MessageLite*>’ used in nested name specifier
394 | static_assert(__is_invocable<deleter_type&, pointer>::value,
| ^~~~~
/usr/include/c++/14/type_traits: In instantiation of ‘struct decay<char*&>’:
/usr/include/c++/14/bits/stl_pair.h:1116:5: required by substitution of ‘template<class _T1, class _T2> constexpr std::pair<typename __strip_reference_wrapper<typename decay<_Tp>::type>::__type, typename __strip_reference_wrapper<typename decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = char*&; _T2 = bool]’
/home/wiktor/opencv_build/opencv/3rdparty/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h:399:24: required from here
/usr/include/c++/14/type_traits:2275:13: error: invalid use of incomplete type ‘struct __decay_selector<char*>’
2275 | { using type = typename __decay_selector<_Tp>::type; };
| ^~~~
/usr/include/c++/14/type_traits:2252:12: note: declaration of ‘struct __decay_selector<char*>’
2252 | struct __decay_selector
| ^~~~~~~~~~~~~~~~
In file included from /home/wiktor/opencv_build/opencv/3rdparty/protobuf/src/google/protobuf/io/zero_copy_stream_impl.h:49,
from /home/wiktor/opencv_build/opencv/3rdparty/protobuf/src/google/protobuf/io/zero_copy_stream_impl.cc:49:
/home/wiktor/opencv_build/opencv/3rdparty/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h: In function ‘std::pair<char*, bool> google::protobuf::io::as_string_data(std::string*)’:
/home/wiktor/opencv_build/opencv/3rdparty/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h:399:24: error: no matching function for call to ‘make_pair(char*&, bool)’
399 | return std::make_pair(p, true);
| ~~~~~~~~~~~~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1116:5: note: candidate: ‘template<class _T1, class _T2> constexpr std::pair<typename __strip_reference_wrapper<typename decay<_Tp>::type>::__type, typename __strip_reference_wrapper<typename decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&)’
1116 | make_pair(_T1&& __x, _T2&& __y)
| ^~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1116:5: note: substitution of deduced template arguments resulted in errors seen above
make[2]: *** [3rdparty/protobuf/CMakeFiles/libprotobuf.dir/build.make:216: 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/io/zero_copy_stream_impl.cc.o] Error 1
make[2]: *** [3rdparty/protobuf/CMakeFiles/libprotobuf.dir/build.make:132: 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/generated_message_util.cc.o] Error 1
make[2]: *** [3rdparty/protobuf/CMakeFiles/libprotobuf.dir/build.make:118: 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/extension_set.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:4362: 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/all] Error 2
[ 3%] Built target ippiw
[ 3%] Linking C static library ../../lib/liblibopenjp2.a
[ 3%] Built target libopenjp2
make: *** [Makefile:166: all] Error 2
I think this article is the more representative of what I tried to achieve:
https://netcloud24.com/index.php?rp=/knowledgebase/108/-How-to-Install-Open-Source-Computer-Vision-Library-OpenCV-on-Ubuntu-22.04.html
In the meantime, I installed clang, g++ 11,12,13,14 and gcc 11,12,13,14. For 14 I needed even to upgrade my Ubuntu system to 24, but I was able to do it(there was a little rgb color loose, I lost red colors, blue was switching with orange etc., and also boot problem, but I needed to enable secure boot in bios, and disable it again).
I also added some env variables:
LIBCLANG_PATH=/usr/lib/llvm-18/lib/ (with symbolic link from /usr/lib/llvm-18/lib/libclang.so.1 to /usr/lib/llvm-18/lib/libclang.so)
Some .bashrc:
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/usr/lib/pkgconfig"
export CXXFLAGS="-std=c++14 -isystem /usr/include/c++/14"
export OPENCV_INCLUDE_PATHS="/usr/local/include/opencv4/"
# export OPENCV_INCLUDE_PATHS="/usr/local/include/"
export OPENCV_LINK_PATHS="/usr/lib/x86_64-linux-gnu/"
export OPENCV_LINK_LIBS="opencv_core,opencv_imgproc"
export LIBCLANG_PATH="/usr/lib/llvm-18/lib/"
,
but it still doesn’t work.