【问题标题】:"ld: symbol(s) not found for architecture x86_64" for OpenCV 3OpenCV 3 的“ld:未找到架构 x86_64 的符号”
【发布时间】: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
  • 请在这里分享您的解决方案

标签: c++ eclipse macos opencv


【解决方案1】:

你可以尝试在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

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

确保检查文件夹以查看您的版本以及它们是否存在等...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-18
    • 2020-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-09
    • 2018-02-20
    • 1970-01-01
    相关资源
    最近更新 更多