当我尝试构建OpenCV应用程序时:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
if (argc < 2) {
cout << "usage: " << argv[0] << " image.png" << endl;
return 1;
}
Mat im = imread(argv[1]);
return 0;
}
我收到链接器错误:
bash-3.2$ g++ `pkg-config --cflags --libs opencv` fs.cpp
Undefined symbols for architecture x86_64:
"cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
_main in fs-EK7vjB.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
以下是我要链接的库(通过自制软件安装的OpenCV):
bash-3.2$ pkg-config --libs opencv
/usr/local/Cellar/opencv/2.4.5/lib/libopencv_calib3d.dylib /usr/local/Cellar/opencv/2.4.5/lib/libopencv_contrib.dylib /usr/local/Cellar/opencv/2.4.5/lib/libopencv_core.dylib /usr/local/Cellar/opencv/2.4.5/lib/libopencv_features2d.dylib /usr/local/Cellar/opencv/2.4.5/lib/libopencv_flann.dylib /usr/local/Cellar/opencv/2.4.5/lib/libopencv_gpu.dylib /usr/local/Cellar/opencv/2.4.5/lib/libopencv_highgui.dylib /usr/local/Cellar/opencv/2.4.5/lib/libopencv_imgproc.dylib /usr/local/Cellar/opencv/2.4.5/lib/libopencv_legacy.dylib /usr/local/Cellar/opencv/2.4.5/lib/libopencv_ml.dylib /usr/local/Cellar/opencv/2.4.5/lib/libopencv_nonfree.dylib /usr/local/Cellar/opencv/2.4.5/lib/libopencv_objdetect.dylib /usr/local/Cellar/opencv/2.4.5/lib/libopencv_ocl.dylib /usr/local/Cellar/opencv/2.4.5/lib/libopencv_photo.dylib /usr/local/Cellar/opencv/2.4.5/lib/libopencv_stitching.dylib /usr/local/Cellar/opencv/2.4.5/lib/libopencv_superres.dylib /usr/local/Cellar/opencv/2.4.5/lib/libopencv_ts.dylib /usr/local/Cellar/opencv/2.4.5/lib/libopencv_video.dylib /usr/local/Cellar/opencv/2.4.5/lib/libopencv_videostab.dylib
稍微可读的列表:
bash-3.2$ for f in $(pkg-config --libs opencv); do echo $(basename $f); done
libopencv_calib3d.dylib
libopencv_contrib.dylib
libopencv_core.dylib
libopencv_features2d.dylib
libopencv_flann.dylib
libopencv_gpu.dylib
libopencv_highgui.dylib
libopencv_imgproc.dylib
libopencv_legacy.dylib
libopencv_ml.dylib
libopencv_nonfree.dylib
libopencv_objdetect.dylib
libopencv_ocl.dylib
libopencv_photo.dylib
libopencv_stitching.dylib
libopencv_superres.dylib
libopencv_ts.dylib
libopencv_video.dylib
libopencv_videostab.dylib
我做错了什么,我怎样才能让事情奏效?
答案 0 :(得分:1)
看起来您没有为系统链接正确的库。尝试使用CMake创建项目文件(详情请参阅我的回答here。)
答案 1 :(得分:0)
看起来OpenCV的自制安装已经破了。我从源代码构建了库并且它工作正常。
此外,您可能想要删除破碎的自制软件opencv:
brew uninstall opencv