【发布时间】:2016-01-08 02:20:02
【问题描述】:
我已经在 mac Yosemite 上使用 CMAKE 安装了 OPENCV 3。我正在使用 Eclipse IDE,在构建解决方案时显示错误:
g++ -L/usr/local/lib -o "test1" ./main.o -lopencv_imgcodecs -lopencv_highgui -lopencv_core
Undefined symbols for architecture x86_64:
"cv::VideoCapture::read(cv::_OutputArray const&)", referenced from:
_main in main.o
"cv::VideoCapture::VideoCapture(int)", referenced from:
_main in main.o
"cv::VideoCapture::~VideoCapture()", referenced from:
_main in main.o
"cv::VideoCapture::get(int) const", referenced from:
_main in main.o
"cv::VideoCapture::isOpened() const", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [test1] Error 1
我在设置中添加了头文件和库。请帮我摆脱这个错误。 提前致谢
代码:
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
VideoCapture cap(0); // open the video camera no. 0
if (!cap.isOpened()) // if not success, exit program
{
cout << "Cannot open the video cam" << endl;
return -1;
}
double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
cout << "Frame size : " << dWidth << " x " << dHeight << endl;
namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
while (1)
{
Mat frame;
bool bSuccess = cap.read(frame); // read a new frame from video
if (!bSuccess) //if not success, break loop
{
cout << "Cannot read a frame from video stream" << endl;
break;
}
imshow("MyVideo", frame); //show the frame in "MyVideo" window
if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
break;
}
}
return 0;
}
【问题讨论】:
-
这对我来说也一直很痛苦,我不确定我是如何解决的。您现在(在 Eclipse 中)是否使用与在 cmake 中构建库时相同的编译器(clang、gcc)?
-
是的,幸运的是我通过添加一些在 youtube 视频中提到的库文件解决了这个问题。
-
你需要链接到
libopencv_videoio -
请在这里分享您的解决方案