Xcode 5的OpenCV编译错误

时间:2014-06-17 05:42:36

标签: xcode opencv compiler-errors

同样的错误:

Undefined symbols for architecture x86_64:
  "cv::applyColorMap(cv::_InputArray const&, cv::_OutputArray const&, int)", referenced from:
      _main in test.o
  "cv::subspaceProject(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&)", referenced from:
      _main in test.o
  "cv::subspaceReconstruct(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&)", referenced from:
      _main in test.o
  "cv::createEigenFaceRecognizer(int, double)", referenced from:
      _main in test.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我尝试的代码是:

https://gist.github.com/hihell/0520674421fe0cb26d38

我已经将C ++标准库更改为"编译器默认"但错误仍然存​​在。

然而,其他简单的代码,如显示图片或打开相机,可以使用相同的设置正常工作。

版本:

  • OpenCV由brew安装,版本2.4.8
  • Xcode版本5.1.1
  • OSX版本10.9.3任何人都可以帮助我吗?

任何帮助或提示都非常受欢迎

1 个答案:

答案 0 :(得分:0)

您需要正确指出标题和库搜索路径。

您似乎已正确设置标题路径 要设置库搜索路径,请执行以下操作:

  1. 找到"图书馆搜索路径"项目的Xcode中的设置。 Build Settings -> Search Paths -> Library Search Paths。然后在Debug或Release中,添加OpenCV库路径。 (就我而言,它是&usr / local / lib。)

  2. 查找:Buid Phases -> Link Binary With Libraries,添加* .dylib文件 就我而言,我补充说:

    • libopencv_contrib.2.4.9.dylib
    • libopencv_core.2.4.9.dylib
    • libopencv_highgui.2.4.9.dylib
    • libopencv_imgproc.2.4.9.dylib
  3. 注意,libopencv_contrib.2.4.9.dylib对于您提到的功能至关重要,也可能需要其他功能。

    顺便说一句,如果您在添加头文件时遇到问题,那就差不多了。在Build Settings -> Search Paths -> Header Search Paths下添加它们。