1

我已经使用以下命令从OpenCV官方代码版本 4.2.0成功配置了我的 OpenCV:

pkg-config --cflags --libs opencv

配置后的输出如下:

-I/home/blaster/installed/include/opencv4/opencv -I/home/blaster/installed/include/opencv4 -L/home/blaster/installed/lib -lopencv_gapi -lopencv_stitching -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_highgui -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hfs -lopencv_img_hash -lopencv_line_descriptor -lopencv_quality -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_optflow -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_dnn -lopencv_plot -lopencv_videostab -lopencv_videoio -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_imgproc -lopencv_core

配置后,我尝试使用以下命令在具有Ubuntu 20.04.1的设备上运行代码:

g++ `pkg-config --cflags --libs opencv` prog.cpp

并得到这个错误:

    cv::VideoCapture::VideoCapture(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
    /usr/bin/ld: prog.cpp:(.text+0x89): undefined reference to `cv::VideoCapture::isOpened() const'
    /usr/bin/ld: prog.cpp:(.text+0xc1): undefined reference to `cv::VideoCapture::get(int) const'
    /usr/bin/ld: prog.cpp:(.text+0x107): undefined reference to `cv::namedWindow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
    /usr/bin/ld: prog.cpp:(.text+0x15d): undefined reference to `cv::VideoCapture::read(cv::_OutputArray const&)'
    /usr/bin/ld: prog.cpp:(.text+0x1ed): undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
    /usr/bin/ld: prog.cpp:(.text+0x224): undefined reference to `cv::waitKey(int)'
    /usr/bin/ld: prog.cpp:(.text+0x264): undefined reference to `cv::VideoCapture::~VideoCapture()'
    /usr/bin/ld: prog.cpp:(.text+0x363): undefined reference to `cv::VideoCapture::~VideoCapture()'
    /usr/bin/ld: /tmp/cc6PCHzq.o: in function `cv::Mat::~Mat()':
    prog.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x3d): undefined reference to `cv::fastFree(void*)'
    /usr/bin/ld: /tmp/cc6PCHzq.o: in function `cv::Mat::release()':
    prog.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4f): undefined reference to `cv::Mat::deallocate()'
    collect2: error: ld returned 1 exit status

如何解决这个问题?

4

0 回答 0