2 installed open cv and g++ compile error

I wrote a cpp code and I want to compile it in my Desktop directory with g++ I have opencv library errors like:

g++ camcalib.cpp -O3 -l/usr/local/include/opencv4** -lopencv_imgproc -lopencv_highgui -lopencv_calib3d 
camcalib.cpp:1:10: fatal error: opencv2/opencv.hpp: No such file or directory
 #include <opencv2/opencv.hpp>
          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.

I searched about in forum and I got some outputs:

pkg-config opencv4 --libs --cflags
-I/usr/local/include/opencv4 -L/usr/local/lib -lopencv_gapi -lopencv_stitching -lopencv_alphamat -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_cudabgsegm -lopencv_cudafeatures2d -lopencv_cudaobjdetect -lopencv_cudastereo -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_highgui -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_quality -lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_cudacodec -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_dnn -lopencv_plot -lopencv_videostab -lopencv_cudaoptflow -lopencv_optflow -lopencv_cudalegacy -lopencv_videoio -lopencv_cudawarping -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_cudaimgproc -lopencv_cudafilters -lopencv_imgproc -lopencv_cudaarithm -lopencv_core -lopencv_cudev

then,

dpkg -l | grep opencv
ii  libopencv                                  4.1.1-2-gd5a58aa75                         arm64        Open Computer Vision Library
ii  libopencv-calib3d3.2:arm64                 3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision Camera Calibration library
ii  libopencv-contrib3.2:arm64                 3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision contrlib library
ii  libopencv-core3.2:arm64                    3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision core library
ii  libopencv-dev                              4.1.1-2-gd5a58aa75                         arm64        Development files for Open Source Computer Vision Library
ii  libopencv-features2d3.2:arm64              3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision Feature Detection and Descriptor Extraction library
ii  libopencv-flann3.2:arm64                   3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision Clustering and Search in Multi-Dimensional spaces library
ii  libopencv-highgui3.2:arm64                 3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision High-level GUI and Media I/O library
ii  libopencv-imgcodecs3.2:arm64               3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision Image Codecs library
ii  libopencv-imgproc3.2:arm64                 3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision Image Processing library
ii  libopencv-ml3.2:arm64                      3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision Machine Learning library
ii  libopencv-objdetect3.2:arm64               3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision Object Detection library
ii  libopencv-photo3.2:arm64                   3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision computational photography library
ii  libopencv-shape3.2:arm64                   3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision shape descriptors and matchers library
ii  libopencv-stitching3.2:arm64               3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision image stitching library
ii  libopencv-superres3.2:arm64                3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision Super Resolution library
ii  libopencv-video3.2:arm64                   3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision Video analysis library
ii  libopencv-videoio3.2:arm64                 3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision Video I/O library
ii  libopencv-videostab3.2:arm64               3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision video stabilization library
ii  libopencv-viz3.2:arm64                     3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision 3D data visualization library
ii  python-opencv                              3.2.0+dfsg-4ubuntu0.1                      arm64        Python bindings for the computer vision library
ii  python3-opencv                             3.2.0+dfsg-4ubuntu0.1                      arm64        Python 3 bindings for the computer vision library

I got the info also:

>>> print(cv2.getBuildInformation())

General configuration for OpenCV 4.4.0 =====================================
  Version control:               4.4.0

  Extra modules:
    Location (extra):            /tmp/build_opencv/opencv_contrib/modules
    Version control (extra):     4.4.0

  Platform:
    Timestamp:                   2022-04-04T06:39:52Z
    Host:                        Linux 4.9.253-tegra aarch64
    CMake:                       3.10.2
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               RELEASE

  CPU/HW features:
    Baseline:                    NEON FP16
      required:                  NEON
      disabled:                  VFPV3

  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ Compiler:                /usr/bin/c++  (ver 7.5.0)
    C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  /usr/bin/cc
    C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,--gc-sections -Wl,--as-needed  
    Linker flags (Debug):        -Wl,--gc-sections -Wl,--as-needed  
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:          m pthread cudart_static -lpthread dl rt nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/local/cuda/lib64 -L/usr/lib/aarch64-linux-gnu
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 alphamat aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor ml objdetect optflow phase_unwrapping photo plot python2 python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    world
    Disabled by dependency:      -
    Unavailable:                 cnn_3dobj cvv hdf java js julia matlab ovis sfm ts viz
    Applications:                apps
    Documentation:               NO
    Non-free algorithms:         YES

  GUI: 
    GTK+:                        YES (ver 3.22.30)
      GThread :                  YES (ver 2.56.4)
      GtkGlExt:                  NO
    OpenGL support:              NO
    VTK support:                 NO

  Media I/O: 
    ZLib:                        /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)
    JPEG:                        /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 80)
    WEBP:                        build (ver encoder: 0x020f)
    PNG:                         /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.34)
    TIFF:                        /usr/lib/aarch64-linux-gnu/libtiff.so (ver 42 / 4.0.9)
    JPEG 2000:                   build Jasper (ver 1.900.1)
    OpenEXR:                     /usr/lib/aarch64-linux-gnu/libImath.so /usr/lib/aarch64-linux-gnu/libIlmImf.so /usr/lib/aarch64-linux-gnu/libIex.so /usr/lib/aarch64-linux-gnu/libHalf.so /usr/lib/aarch64-linux-gnu/libIlmThread.so (ver 2_2)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      YES (2.2.5)
    FFMPEG:                      YES
      avcodec:                   YES (57.107.100)
      avformat:                  YES (57.83.100)
      avutil:                    YES (55.78.100)
      swscale:                   YES (4.8.100)
      avresample:                YES (3.7.0)
    GStreamer:                   YES (1.14.5)
    v4l/v4l2:                    YES (linux/videodev2.h)

  Parallel framework:            pthreads

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Lapack:                      YES (/usr/lib/aarch64-linux-gnu/liblapack.so /usr/lib/aarch64-linux-gnu/libcblas.so /usr/lib/aarch64-linux-gnu/libatlas.so)
    Eigen:                       YES (ver 3.3.4)
    Custom HAL:                  YES (carotene (ver 0.0.1))
    Protobuf:                    build (3.5.1)

  NVIDIA CUDA:                   YES (ver 10.2, CUFFT CUBLAS FAST_MATH)
    NVIDIA GPU arch:             53 62 72
    NVIDIA PTX archs:

  cuDNN:                         YES (ver 8.0)

  OpenCL:                        YES (no extra features)
    Include path:                /tmp/build_opencv/opencv/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python 2:
    Interpreter:                 /usr/bin/python2.7 (ver 2.7.17)
    Libraries:                   /usr/lib/aarch64-linux-gnu/libpython2.7.so (ver 2.7.17)
    numpy:                       /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.13.3)
    install path:                lib/python2.7/dist-packages/cv2/python-2.7

  Python 3:
    Interpreter:                 /usr/bin/python3 (ver 3.6.9)
    Libraries:                   /usr/lib/aarch64-linux-gnu/libpython3.6m.so (ver 3.6.9)
    numpy:                       /usr/lib/python3/dist-packages/numpy/core/include (ver 1.13.3)
    install path:                lib/python3.6/dist-packages/cv2/python-3.6

  Python (for build):            /usr/bin/python2.7

  Java:                          
    ant:                         NO
    JNI:                         NO
    Java wrappers:               NO
    Java tests:                  NO

  Install to:                    /usr/local
-----------------------------------------------------------------

it seems I have two different version of opencv , in the begining I downgraded my opencv version from opencv.4sth
to opencv3.2 but I upgraded again using this repo in github, I have still g++ issue that I mentioned aboveI recognized that I have to use opencv3 n-because ROS Melodic supports opencv3, how can Isolve my g++ issue. Could you helpme with that issue?

Hi,
We have OpenCV samples in
L4T Driver Package (BSP) Sources

Please check if you can compile the samples. If not we woudl suggest re-install the system image and SDK components to usedefault 4.1.1.

I install and go to file that I extraxted opencv folder and run like :

~/opencvgpp/opencv-sample-apps/opencv_camera$ g++ opencv_gst_camera.cpp -o opencv_gs_camera_cpp
/tmp/cc7xdTKv.o: In function `main':
opencv_gst_camera.cpp:(.text+0x238): undefined reference to `cv::VideoCapture::VideoCapture()'
opencv_gst_camera.cpp:(.text+0x290): undefined reference to `cv::CommandLineParser::CommandLineParser(int, char const* const*, cv::String const&)'
opencv_gst_camera.cpp:(.text+0x2b4): undefined reference to `cv::CommandLineParser::has(cv::String const&) const'
opencv_gst_camera.cpp:(.text+0x35c): undefined reference to `cv::CommandLineParser::check() const'
opencv_gst_camera.cpp:(.text+0x378): undefined reference to `cv::CommandLineParser::printErrors() const'
opencv_gst_camera.cpp:(.text+0x3c0): undefined reference to `cv::VideoCapture::open(cv::String const&, int)'
opencv_gst_camera.cpp:(.text+0x3d8): undefined reference to `cv::VideoCapture::isOpened() const'
opencv_gst_camera.cpp:(.text+0x430): undefined reference to `cv::VideoCapture::operator>>(cv::Mat&)'
opencv_gst_camera.cpp:(.text+0x434): undefined reference to `cv::VideoCapture::operator>>(cv::Mat&)'
opencv_gst_camera.cpp:(.text+0x468): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
opencv_gst_camera.cpp:(.text+0x480): undefined reference to `cv::waitKey(int)'
opencv_gst_camera.cpp:(.text+0x54c): undefined reference to `cv::VideoCapture::release()'
opencv_gst_camera.cpp:(.text+0x558): undefined reference to `cv::CommandLineParser::~CommandLineParser()'
opencv_gst_camera.cpp:(.text+0x570): undefined reference to `cv::VideoCapture::~VideoCapture()'
opencv_gst_camera.cpp:(.text+0x638): undefined reference to `cv::CommandLineParser::~CommandLineParser()'
opencv_gst_camera.cpp:(.text+0x658): undefined reference to `cv::VideoCapture::~VideoCapture()'
/tmp/cc7xdTKv.o: In function `cv::String::String(char const*)':
opencv_gst_camera.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x40): undefined reference to `cv::String::allocate(unsigned long)'
/tmp/cc7xdTKv.o: In function `cv::String::~String()':
opencv_gst_camera.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x10): undefined reference to `cv::String::deallocate()'
/tmp/cc7xdTKv.o: In function `cv::Mat::~Mat()':
opencv_gst_camera.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x34): undefined reference to `cv::fastFree(void*)'
/tmp/cc7xdTKv.o: In function `cv::Mat::release()':
opencv_gst_camera.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x58): undefined reference to `cv::Mat::deallocate()'
/tmp/cc7xdTKv.o: In function `cv::String::String(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
opencv_gst_camera.cpp:(.text._ZN2cv6StringC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN2cv6StringC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x54): undefined reference to `cv::String::allocate(unsigned long)'
/tmp/cc7xdTKv.o: In function `cv::TickMeter::start()':
opencv_gst_camera.cpp:(.text._ZN2cv9TickMeter5startEv[_ZN2cv9TickMeter5startEv]+0xc): undefined reference to `cv::getTickCount()'
/tmp/cc7xdTKv.o: In function `cv::TickMeter::stop()':
opencv_gst_camera.cpp:(.text._ZN2cv9TickMeter4stopEv[_ZN2cv9TickMeter4stopEv]+0xc): undefined reference to `cv::getTickCount()'
/tmp/cc7xdTKv.o: In function `cv::TickMeter::getTimeSec() const':
opencv_gst_camera.cpp:(.text._ZNK2cv9TickMeter10getTimeSecEv[_ZNK2cv9TickMeter10getTimeSecEv]+0x1c): undefined reference to `cv::getTickFrequency()'
/tmp/cc7xdTKv.o: In function `unsigned int cv::CommandLineParser::get<unsigned int>(cv::String const&, bool) const':
opencv_gst_camera.cpp:(.text._ZNK2cv17CommandLineParser3getIjEET_RKNS_6StringEb[_ZNK2cv17CommandLineParser3getIjEET_RKNS_6StringEb]+0x44): undefined reference to `cv::CommandLineParser::getByName(cv::String const&, bool, int, void*) const'
/tmp/cc7xdTKv.o: In function `int cv::CommandLineParser::get<int>(cv::String const&, bool) const':
opencv_gst_camera.cpp:(.text._ZNK2cv17CommandLineParser3getIiEET_RKNS_6StringEb[_ZNK2cv17CommandLineParser3getIiEET_RKNS_6StringEb]+0x44): undefined reference to `cv::CommandLineParser::getByName(cv::String const&, bool, int, void*) const'
collect2: error: ld returned 1 exit status

Why is it happening I didn’t get it.
Do I have to do sth with MakeFile?

Hi,
Are you able to build on Jetson Nano? The Makefile is for building the samples on Jetson platforms.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.