将错误与简单的OpenCV程序链接

时间:2015-06-01 19:12:17

标签: c++ macos opencv linker clang

我是OpenCV的新手,我似乎无法获得一个简单的程序。当我尝试编译时,我遇到链接错误,我似乎无法弄清楚原因。

以下是代码:

#include "opencv2/highgui/highgui.hpp" 
#include "opencv2/core/core.hpp" 
#include <iostream> 

using namespace cv;
using namespace std;

int main () { 
  VideoCapture webcam = VideoCapture (0); 

  if (webcam.isOpened () == false) { 
    cout << "Opening camera failed." << endl; 
    return 0; 
  } 

  namedWindow ("Webcam", WINDOW_AUTOSIZE); 
  Mat frame; 

  while (true) { 
    webcam >> frame; //OR webcam.read (frame) 
    imshow ("Webcam", frame); 
  } 

  return 0; 
}

我正在尝试使用以下命令从命令行编译它:

clang++ Test.cpp -o test -I/usr/local/Cellar/opencv/2.4.11_1/include/ -L/usr/local/Cellar/opencv/2.4.11_1/lib  -lopencv_core -lopencv_highgui -stdlib=libstdc++

以下是错误消息:

Undefined symbols for architecture x86_64:
  "cv::namedWindow(std::string const&, int)", referenced from:
      _main in Test-768b08.o
  "cv::imshow(std::string const&, cv::_InputArray const&)", referenced from:
      _main in Test-768b08.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我正在使用Mac OS X 10.9并使用Homebrew安装了OpenCV。任何建议都表示赞赏。

0 个答案:

没有答案
相关问题