使用openCV时如何修复链接器错误?

时间:2015-05-28 11:06:47

标签: c++ opencv c++11 linker

我试图在我的mac上设置openCV并使用C ++在Eclipse中使用它。 但我认为链接器有问题。 我在此处描述了所有库:http://docs.opencv.org/doc/tutorials/introduction/linux_eclipse/linux_eclipse.html

我尝试了链接器命令g++g++ -std=c++11,但始终收到相同的错误消息:

g++ -L/usr/local/lib -o camera src/Camera.o -lopencv_core -lopencv_ml -
lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_flann -lopencv_imgproc -lopencv_highgui 
Undefined symbols for architecture x86_64:
  "cv::imread(cv::String const&, int)", referenced from:
      _main in Camera.o
ld: symbol(s) not found for architecture x86_64

代码如下:

#include "/usr/local/include/opencv/cv.hpp"
#include "/usr/local/include/opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
  Mat image;
  image = imread( argv[1], 1 );

  if( argc != 2 || !image.data )
    {
      printf( "No image data \n" );
      return -1;
    }

  namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
  imshow( "Display Image", image );

  waitKey(0);

  return 0;
}

1 个答案:

答案 0 :(得分:4)

imread已在opencv_imgcodecs库中移动。

尝试将-lopencv_imgcodecs添加到链接器标志。