OpenCV 3 的"ld: symbol(s) not found for architecture x86_64"

"ld: symbol(s) not found for architecture x86_64" for OpenCV 3

本文关键字:for found not architecture x86 ld symbol OpenCV      更新时间:2023-10-16

我已经在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;
}

您可以尝试在macos上这样编译:

g++ -I /usr/local/Cellar/opencv/4.5.0_5/include/opencv4/ -L /usr/local/Cellar/opencv/4.5.0_5/lib-l opencv_core -l opencv_imgcodecs -l opencv_imgproc -l opencv_highgui -l opencv_videoio <filename>.cpp

你可能需要或多或少在你的编译,但关键是库被链接,据我所知。

Make Sure检查文件夹以查看您的版本以及它们是否存在等