使用openCV编译程序时Collect2 ld错误

时间:2019-09-05 20:55:14

标签: c++ opencv ld

当使用opencv2编译程序时,ld出现了奇怪的编译器错误。我找不到与该错误有关的任何在线信息。

我正在使用此命令来编译程序

function capitalPermutations(word) { var result = [''], temp, i, j, upper, lower; for (i = 0; i < word.length; i++) { temp = result; result = []; lower = word[i].toLowerCase(); upper = word[i].toUpperCase(); for (j = 0; j < temp.length; j++) { result.push(temp[j] + lower, temp[j] + upper); } } return result; } console.log(capitalPermutations('abc'));

我从编译器得到了这个输出

g++ -Wall Tracker.cpp -o Tracker

Tracker.cpp

Tracker.cpp: In function ‘int main(int, char**)’:
Tracker.cpp:60:10: warning: unused variable ‘ok’ [-Wunused-variable]
   60 |     bool ok = video.read(frame);
      |          ^~
/usr/bin/ld: /tmp/cc2Q6W8D.o: in function `main':
Tracker.cpp:(.text+0x29d): undefined reference to `cv::VideoCapture::VideoCapture(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
/usr/bin/ld: Tracker.cpp:(.text+0x2ca): undefined reference to `cv::VideoCapture::isOpened() const'
/usr/bin/ld: Tracker.cpp:(.text+0x34a): undefined reference to `cv::VideoCapture::read(cv::_OutputArray const&)'
/usr/bin/ld: Tracker.cpp:(.text+0x425): undefined reference to `cv::rectangle(cv::_InputOutputArray const&, cv::Rect_<int>, cv::Scalar_<double> const&, int, int, int)'
/usr/bin/ld: Tracker.cpp:(.text+0x492): undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
/usr/bin/ld: Tracker.cpp:(.text+0x503): undefined reference to `cv::Tracker::init(cv::_InputArray const&, cv::Rect_<double> const&)'
/usr/bin/ld: Tracker.cpp:(.text+0x544): undefined reference to `cv::VideoCapture::read(cv::_OutputArray const&)'
/usr/bin/ld: Tracker.cpp:(.text+0x562): undefined reference to `cv::getTickCount()'
/usr/bin/ld: Tracker.cpp:(.text+0x5b3): undefined reference to `cv::Tracker::update(cv::_InputArray const&, cv::Rect_<double>&)'
/usr/bin/ld: Tracker.cpp:(.text+0x5cd): undefined reference to `cv::getTickFrequency()'
/usr/bin/ld: Tracker.cpp:(.text+0x5da): undefined reference to `cv::getTickCount()'
/usr/bin/ld: Tracker.cpp:(.text+0x697): undefined reference to `cv::rectangle(cv::_InputOutputArray const&, cv::Rect_<int>, cv::Scalar_<double> const&, int, int, int)'
/usr/bin/ld: Tracker.cpp:(.text+0x772): undefined reference to `cv::putText(cv::_InputOutputArray const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'
/usr/bin/ld: Tracker.cpp:(.text+0x86e): undefined reference to `cv::putText(cv::_InputOutputArray const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'
/usr/bin/ld: Tracker.cpp:(.text+0x9ab): undefined reference to `cv::putText(cv::_InputOutputArray const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'
/usr/bin/ld: Tracker.cpp:(.text+0xa49): undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
/usr/bin/ld: Tracker.cpp:(.text+0xa80): undefined reference to `cv::waitKey(int)'
/usr/bin/ld: Tracker.cpp:(.text+0xab8): undefined reference to `cv::VideoCapture::~VideoCapture()'
/usr/bin/ld: Tracker.cpp:(.text+0xe35): undefined reference to `cv::VideoCapture::~VideoCapture()'
/usr/bin/ld: /tmp/cc2Q6W8D.o: in function `cv::Mat::~Mat()':
Tracker.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/usr/bin/ld: /tmp/cc2Q6W8D.o: in function `cv::Mat::release()':
Tracker.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()'
collect2: error: ld returned 1 exit status

我以前从未见过这种错误,而且我不确定是什么原因造成的,任何帮助都将是很好的。

1 个答案:

答案 0 :(得分:0)

您好像忘了链接,也许是这样的:

g++ -Wall Tracker.cpp -o Tracker -lopencv_core -lopencv_imgproc -lopencv_dnn -lopencv_highgui

根据版本,您可能还需要添加-lopencv_videoio