试图编译一个简单的opencv c ++文件

时间:2014-04-08 10:22:35

标签: c++ opencv

我是新手来开cv。目前我正试图测试我是否可以运行一个简单的文件。

// Example showing how to read and write images
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv/cvaux.h>

int main(int argc, char** argv)
{
  IplImage * pInpImg = 0;

  // Load an image from file - change this based on your image name
  pInpImg = cvLoadImage("bear.jpg", CV_LOAD_IMAGE_UNCHANGED);
  if(!pInpImg)
  {
    fprintf(stderr, "failed to load input image\n");
    return -1;
  }

  // Write the image to a file with a different name,
  // using a different image format -- .png instead of .jpg
  if( !cvSaveImage("my_image_copy.png", pInpImg) )
  {
    fprintf(stderr, "failed to write image file\n");
  }

  // Remember to free image memory after using it!
  cvReleaseImage(&pInpImg);

  return 0;
}

我编译了它:

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

我收到了这个错误:

Undefined symbols for architecture x86_64:
  "_cvLoadImage", referenced from:
      _main in cv-zQ5X30.o
  "_cvReleaseImage", referenced from:
      _main in cv-zQ5X30.o
  "_cvSaveImage", referenced from:
      _main in cv-zQ5X30.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我迷失在这里,非常感谢任何帮助。 谢谢。

1 个答案:

答案 0 :(得分:1)

我认为问题可能是使用“-libs”和“-cflags”而不是“--libs”和“--cflags”,请改用:

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