Неопределенные ссылочные ошибки для OpenCV Hello World в Ubuntu - PullRequest
0 голосов
/ 11 июня 2019

Я пытаюсь следующий код:

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

using namespace cv;

int main(int argc, char** argv) {
    namedWindow("Output",1);
    Mat output = Mat::zeros( 120, 350, CV_8UC3 );
    putText(output,"Hello World",cvPoint(15,70),
            FONT_HERSHEY_PLAIN,3,cvScalar(0,255,0),4);
    imshow("Output", output);
    waitKey(0);
    return 0;

}

Затем я попытался g++ -I/usr/local/include -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui opencv_hello.cpp -o opencv_hello и g++ pkg-config opencv cvblob --cflags --libs opencv_hello.cpp -o opencv_hello

Но они оба выдают одинаковые undefined reference ошибки:

opencv_hello.cpp:(.text+0x132): undefined reference to `cv::namedWindow(cv::String const&, int)'
opencv_hello.cpp:(.text+0x15f): undefined reference to `cv::Mat::zeros(int, int, int)'
opencv_hello.cpp:(.text+0x26f): undefined reference to `cv::putText(cv::_InputOutputArray const&, cv::String const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'
opencv_hello.cpp:(.text+0x2d7): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
opencv_hello.cpp:(.text+0x2ff): undefined reference to `cv::waitKey(int)'
/tmp/cctt8VGQ.o: In function `cv::String::String(char const*)':
opencv_hello.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4d): undefined reference to `cv::String::allocate(unsigned long)'
/tmp/cctt8VGQ.o: In function `cv::String::~String()':
opencv_hello.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
/tmp/cctt8VGQ.o: In function `cv::Mat::~Mat()':
opencv_hello.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/cctt8VGQ.o: In function `cv::Mat::release()':
opencv_hello.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()'

Как я могу это исправить?

1 Ответ

0 голосов
/ 11 июня 2019

Если команда pkg-config opencv --cflags --libs находит, что OpenCV включает файлы и библиотеки, указанные ниже, компиляция работает без ошибок.

    g++ opencv_hello.cpp -o opencv_hello $(pkg-config opencv --cflags --libs)

или

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