简体   繁体   中英

Opencv in UBUNTU LTS error on basic c++ program

I installed opencv on UBUNTU 18.04 for C++. I used cmake on github source code and build in opencv/release. But writing even a hello world program containing ''' #include ''' is causing error on compiling with g++. The error report is:

在此处输入图片说明

`
In file included from /usr/include/opencv2/highgui.hpp:51,
                 from main.cpp:1:
/usr/include/opencv2/videoio.hpp:928:83: error: invalid use of incomplete type ‘struct cv::DefaultDeleter<CvCapture>’
 template<> CV_EXPORTS void DefaultDeleter<CvCapture>::operator ()(CvCapture* obj) const;
                                                                                   ^~~~~
In file included from /usr/local/include/opencv2/core/cvstd.hpp:81,
                 from /usr/local/include/opencv2/core/base.hpp:58,
                 from /usr/local/include/opencv2/core.hpp:54,
                 from /usr/include/opencv2/highgui.hpp:46,
                 from main.cpp:1:
/usr/local/include/opencv2/core/cvstd_wrapper.hpp:32:29: note: declaration of ‘struct cv::DefaultDeleter<CvCapture>’
 template<typename Y> struct DefaultDeleter;
                             ^~~~~~~~~~~~~~
In file included from /usr/include/opencv2/highgui.hpp:51,
                 from main.cpp:1:
/usr/include/opencv2/videoio.hpp:929:91: error: invalid use of incomplete type ‘struct cv::DefaultDeleter<CvVideoWriter>’
 template<> CV_EXPORTS void DefaultDeleter<CvVideoWriter>::operator ()(CvVideoWriter* obj) const;
                                                                                           ^~~~~
In file included from /usr/local/include/opencv2/core/cvstd.hpp:81,
                 from /usr/local/include/opencv2/core/base.hpp:58,
                 from /usr/local/include/opencv2/core.hpp:54,
                 from /usr/include/opencv2/highgui.hpp:46,
                 from main.cpp:1:
/usr/local/include/opencv2/core/cvstd_wrapper.hpp:32:29: note: declaration of ‘struct cv::DefaultDeleter<CvVideoWriter>’
 template<typename Y> struct DefaultDeleter;
`

Edit: same output on

g++ main.cpp `pkg-config --cflags --libs opencv` -o out 

My code main.cpp is:

#include <opencv2/highgui.hpp>
#include <iostream>

int main( int argc, char** argv ) {

  cv::Mat image;
  image = cv::imread("sample.jpeg" , CV_LOAD_IMAGE_COLOR);

  if(! image.data ) {
      std::cout <<  "Could not open or find the image" << std::endl ;
      return -1;
    }

  cv::namedWindow( "Display window", cv::WINDOW_AUTOSIZE );
  cv::imshow( "Display window", image );

  cv::waitKey(0);
  return 0;
}

The bash output of

pkg-config --cflags --libs opencv

is :

-I/usr/include/opencv -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_datasets -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_line_descriptor -lopencv_optflow -lopencv_video -lopencv_plot -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_rgbd -lopencv_viz -lopencv_surface_matching -lopencv_text -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core

bash output

System configuration:

opencv : 3.2.0

compiler: g++

os : ubuntu

You will need to link OpneCV with your program.

Try the following: g++ main.cpp pkg-config --cflags --libs opencv -o out

pkg-config --cflags --libs opencv will add include_dirs and link_directories .

More explanation here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM