C++ 使用简单OpenCV程序链接错误
我是OpenCV新手,似乎无法使用简单的程序。当我试图编译的时候,我得到了链接错误,我似乎不知道为什么 代码如下:C++ 使用简单OpenCV程序链接错误,c++,macos,opencv,linker,clang,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 = VideoCapt
#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;
}
以下是错误消息:
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,我使用自制软件安装了OpenCV。任何建议都将不胜感激。请尝试:
clang++-Wall-g-o test test.cpp`pkg config--cflags--libs opencv`
。最后一部分应该在编译时方便地包括OpenCV库的所有位置。如果您是通过自制程序安装OpenCV,则应该配置此选项。当我尝试安装OpenCV时,仍然会出现相同的错误。命令grep-ls imshow/usr/local/cillar/OpenCV/2.4.11_1/lib/*
?是否使用Xcode?请尝试:clang++-Wall-g-o test test.cpp`pkg config--cflags--libs OpenCV`
。最后一部分应该在编译时方便地包括OpenCV库的所有位置。如果您是通过自制程序安装OpenCV,则应该配置此选项。当我尝试安装OpenCV时,仍然会出现相同的错误。命令grep-ls imshow/usr/local/cillar/OpenCV/2.4.11_1/lib/*
?是否使用Xcode?请尝试:clang++-Wall-g-o test test.cpp`pkg config--cflags--libs OpenCV`
。最后一部分应该在编译时方便地包括OpenCV库的所有位置。如果您通过自制程序安装OpenCV,则应该配置此选项。当我尝试安装OpenCV时,仍然会出现相同的错误。命令grep-ls imshow/usr/local/ceral/OpenCV/2.4.11_1/lib/*
的结果是什么?您使用的是Xcode吗?
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)