How to install and use opencv in manjaro linux

I’m trying to compile a c++ file using g++ in manjaro linux .
I installed opencv from official manjaro repos but i’m getting warning from vscode

i have also tried adding

`pkg-config --cflags --libs opencv`

to as an argument to g++ but it still fails.
I tried to compile from source and the build but it failed

i tried installing opencv2 from aur and it failed

/home/thenujan/opencv2-opt/src/opencv-2.4.13.6/modules/core/include/opencv2/core/internal.hpp:195:12: fatal error: tbb/tbb_stddef.h: No such file or directory
  195 | #  include "tbb/tbb_stddef.h"
      |            ^~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/build.make:85: modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1817: modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/all] Error 2
make: *** [Makefile:166: all] Error 2
==> ERROR: A failure occurred in build().

locate opencv4.pc returned this

/usr/lib/pkgconfig/opencv4.pc

so i tried

g++ -o out.ou `pkg-config --cflags  opencv4` main.cpp

it worked

And then had to use the one below to avoid some other errors

g++ $(pkg-config opencv4 --cflags) -std=c++17 foo.cpp $(pkg-config opencv4 --libs) -o foo.o
/usr/bin/ld: main.cpp:(.text+0xf9): undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
/usr/bin/ld: main.cpp:(.text+0x130): undefined reference to `cv::waitKey(int)'
/usr/bin/ld: main.cpp:(.text+0x13c): undefined reference to `cv::Mat::~Mat()'
/usr/bin/ld: main.cpp:(.text+0x1cb): undefined reference to `cv::Mat::~Mat()'

this is entirely outdated, no more maintained, do not use that.
please rather build opencv libs locally from github src

1 Like