0

I am trying to build opencv from source to enable GStreamer support. I have followed this instructions here, but an error occurred. More specifically, the error occurred in this step:

make -j$(nproc)

The overall procedure is this one:

sudo apt update 
sudo apt install -y \
    build-essential cmake git pkg-config \
    libjpeg-dev libtiff-dev libpng-dev \
    libavcodec-dev libavformat-dev libswscale-dev \
    libv4l-dev libxvidcore-dev libx264-dev \
    libgtk-3-dev libatlas-base-dev gfortran \
    python3-dev python3-numpy \
    libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
cd ~
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
cd opencv
git checkout 3.4.18  # I used this version because I had the same one working in venv on a pip version
cd ../opencv_contrib
git checkout 3.4.18
cd ~/opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D WITH_GSTREAMER=ON \
      -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
      -D PYTHON3_EXECUTABLE=$(which python3) \
      -D BUILD_opencv_python3=ON \
      -D BUILD_EXAMPLES=OFF ..
make -j$(nproc)  # <- this is where the error is thrown
sudo make install
sudo ldconfig

The error is this one:

[ 43%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/layers/layers_common.avx2.cpp.o
[ 43%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/layers/layers_common.avx512_skx.cpp.o
[ 44%] Linking CXX shared library ../../lib/libopencv_dnn.so
[ 44%] Built target opencv_dnn
[ 44%] Linking CXX shared library ../../lib/libopencv_features2d.so
[ 44%] Built target opencv_features2d
make: *** [Makefile:166: all] Error 2

and as I understand it there is an issue with libopencv_features2d.so library. Inside the build folder there is a lib subfolder which contains libopencv_features2d.so (it is a symlinc to libopencv_features2d.so.3.4.18 in reality).

I tried to apply some flags to the CMake to give more information and to my surprise the process seemed to move forward. I am not sure if it actually fixed the error or just moved on but it reached a point where it doesn't get any better.

[ 44%] Built target opencv_dnn
[ 44%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o
[ 46%] Built target opencv_calib3d
[ 46%] Built target opencv_text
[ 46%] Built target opencv_stereo
[ 46%] Built target opencv_structured_light
[ 47%] Built target opencv_rgbd
[ 48%] Built target opencv_objdetect
[ 49%] Built target opencv_aruco
[ 50%] Built target opencv_xfeatures2d
[ 50%] Built target opencv_bgsegm
[ 52%] Built target opencv_ximgproc
[ 53%] Built target opencv_xobjdetect
[ 54%] Built target opencv_face
[ 56%] Built target opencv_datasets
[ 57%] Built target opencv_stitching
[ 58%] Built target opencv_optflow
[ 61%] Built target opencv_tracking
In file included from /home/gorfanidis/Downloads/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:79,
                 from /home/gorfanidis/Downloads/opencv/modules/videoio/src/cap_ffmpeg.cpp:49:
/home/gorfanidis/Downloads/opencv/modules/videoio/src/ffmpeg_codecs.hpp:80:6: warning: "LIBAVCODEC_VERSION_INT" is not defined, evaluates to 0 [-Wundef]
   80 | #if (LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(54, 51, 100))
      |      ^~~~~~~~~~~~~~~~~~~~~~
/home/gorfanidis/Downloads/opencv/modules/videoio/src/ffmpeg_codecs.hpp:270:5: warning: "LIBAVCODEC_VERSION_INT" is not defined, evaluates to 0 [-Wundef]
  270 | #if LIBAVCODEC_VERSION_INT>0x000409
      |     ^~~~~~~~~~~~~~~~~~~~~~
/home/gorfanidis/Downloads/opencv/modules/videoio/src/ffmpeg_codecs.hpp:277:5: warning: "LIBAVCODEC_VERSION_INT" is not defined, evaluates to 0 [-Wundef]
  277 | #if LIBAVCODEC_VERSION_INT>((50<<16)+(1<<8)+0)
      |     ^~~~~~~~~~~~~~~~~~~~~~
/home/gorfanidis/Downloads/opencv/modules/videoio/src/ffmpeg_codecs.hpp:286:5: warning: "LIBAVCODEC_VERSION_INT" is not defined, evaluates to 0 [-Wundef]
  286 | #if LIBAVCODEC_VERSION_INT>((51<<16)+(11<<8)+0)
      |     ^~~~~~~~~~~~~~~~~~~~~~
/home/gorfanidis/Downloads/opencv/modules/videoio/src/ffmpeg_codecs.hpp:295:5: warning: "LIBAVCODEC_VERSION_INT" is not defined, evaluates to 0 [-Wundef]
  295 | #if LIBAVCODEC_VERSION_INT>=((51<<16)+(49<<8)+0)
      |     ^~~~~~~~~~~~~~~~~~~~~~
/home/gorfanidis/Downloads/opencv/modules/videoio/src/ffmpeg_codecs.hpp:81:26: error: ‘CODEC_ID_H264’ was not declared in this scope; did you mean ‘AV_CODEC_ID_H264’?
   81 | #define AV_CODEC_ID_H264 CODEC_ID_H264
      |                          ^~~~~~~~~~~~~
/home/gorfanidis/Downloads/opencv/modules/videoio/src/ffmpeg_codecs.hpp:146:7: note: in expansion of macro ‘AV_CODEC_ID_H264’
  146 |     { AV_CODEC_ID_H264, MKTAG('H', '2', '6', '4') },
      |       ^~~~~~~~~~~~~~~~
/home/gorfanidis/Downloads/opencv/modules/videoio/src/ffmpeg_codecs.hpp:81:26: error: ‘CODEC_ID_H264’ was not declared in this scope; did you mean ‘AV_CODEC_ID_H264’?
   81 | #define AV_CODEC_ID_H264 CODEC_ID_H264
      |                          ^~~~~~~~~~~~~
/home/gorfanidis/Downloads/opencv/modules/videoio/src/ffmpeg_codecs.hpp:147:7: note: in expansion of macro ‘AV_CODEC_ID_H264’
  147 |     { AV_CODEC_ID_H264, MKTAG('h', '2', '6', '4') },
      |       ^~~~~~~~~~~~~~~~
/home/gorfanidis/Downloads/opencv/modules/videoio/src/ffmpeg_codecs.hpp:81:26: error: ‘CODEC_ID_H264’ was not declared in this scope; did you mean ‘AV_CODEC_ID_H264’?
   81 | #define AV_CODEC_ID_H264 CODEC_ID_H264
      |                          ^~~~~~~~~~~~~
/home/gorfanidis/Downloads/opencv/modules/videoio/src/ffmpeg_codecs.hpp:148:7: note: in expansion of macro ‘AV_CODEC_ID_H264’
  148 |     { AV_CODEC_ID_H264, MKTAG('X', '2', '6', '4') },
      |       ^~~~~~~~~~~~~~~~
/home/gorfanidis/Downloads/opencv/modules/videoio/src/ffmpeg_codecs.hpp:81:26: error: ‘CODEC_ID_H264’ was not declared in this scope; did you mean ‘AV_CODEC_ID_H264’?
   81 | #define AV_CODEC_ID_H264 CODEC_ID_H264
      |                          ^~~~~~~~~~~~~
/home/gorfanidis/Downloads/opencv/modules/videoio/src/ffmpeg_codecs.hpp:149:7: note: in expansion of macro ‘AV_CODEC_ID_H264’
  149 |     { AV_CODEC_ID_H264, MKTAG('x', '2', '6', '4') },
      |       ^~~~~~~~~~~~~~~~
/home/gorfanidis/Downloads/opencv/modules/videoio/src/ffmpeg_codecs.hpp:81:26: error: ‘CODEC_ID_H264’ was not declared in this scope; did you mean ‘AV_CODEC_ID_H264’?
   81 | #define AV_CODEC_ID_H264 CODEC_ID_H264
 ...

After that there is large display of similar messages.

So, is there any action I could take to resolve the issue? Do I need to update any path variable for example?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.