C++无法编译OpenCV程序

2024-09-27 00:17:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经找到了解决办法,但找不到。这对我来说还是新鲜事,所以如果是小事请原谅我。我的操作系统是ubuntu16.04。在

我已经使用pyimagesearch教程安装了与Python绑定的opencv3。这是我见过的最完整的OpenCV安装教程之一。因此,在使用Popthon和OpenCV之后,我需要用C++使用OpenCV来加快游戏。 我已经复制并粘贴了用于从这个site加载和显示C++图像的代码。然后用我的命令编译程序:

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

一开始,我得到了一个错误:

^{pr2}$

找到解决方案后(通过从opencv.pc中删除-lippicv),我得到了以下输出:

/tmp/ccriaGtQ.o: In function `main':
test.cpp:(.text+0x9d): undefined reference to `cv::imread(cv::String    const&, int)'
test.cpp:(.text+0x128): undefined reference to `cv::namedWindow(cv::String const&, int)'
test.cpp:(.text+0x17d): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
test.cpp:(.text+0x1a5): undefined reference to `cv::waitKey(int)'
/tmp/ccriaGtQ.o: In function `cv::String::String(char const*)':
test.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4d): undefined reference to `cv::String::allocate(unsigned long)'
/tmp/ccriaGtQ.o: In function `cv::String::~String()':
test.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined  reference to `cv::String::deallocate()'
/tmp/ccriaGtQ.o: In function `cv::Mat::~Mat()':
test.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined  reference to `cv::fastFree(void*)'
/tmp/ccriaGtQ.o: In function `cv::Mat::operator=(cv::Mat const&)':
test.cpp:(.text._ZN2cv3MataSERKS0_[_ZN2cv3MataSERKS0_]+0x115): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/tmp/ccriaGtQ.o: In function `cv::Mat::release()':
test.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b):    undefined reference to `cv::Mat::deallocate()'
collect2: error: ld returned 1 exit status

我快疯了。我还是这方面的初学者。所以,任何帮助都将不胜感激。在

谢谢。在


Tags: totextinteststringfunctionopencvcpp

热门问题