问题描述
在Mac OSX 10.8,XCode 4.6和C ++中
我正在遵循系统上/opt/local/share/OpenCV/doc
中opencv_tutorials.pdf
中的教程.在第311页上,我们获得了此样本(略作编辑):
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
int main( int argc, char** argv ) {
Mat img_1 = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
int minHessian = 400;
SurfFeatureDetector detector( minHessian );
std::vector<KeyPoint> keypoints_1;
detector.detect( img_1, keypoints_1 );
}
我不得不将上面的代码修改为#include "opencv2/nonFree/features2d.hpp"
,这是我通过运行找到的文件
find /opt/local/include -name "*.hpp" -exec grep SurfFeatureDetector "{}" ';' -print
代码将编译,这意味着在hpp
文件中找到符号detector.detect
,并通过C ++编译器进行类型检查.接下来是尝试查找包含符号的库.
现在,我的发行版中的/opt/local/lib
中有这些库:
libopencv_calib3d.2.4.3.dylib
libopencv_contrib.2.4.3.dylib
libopencv_core.2.4.3.dylib
libopencv_features2d.2.4.3.dylib
libopencv_flann.2.4.3.dylib
libopencv_gpu.2.4.3.dylib
libopencv_highgui.2.4.3.dylib
libopencv_imgproc.2.4.3.dylib
libopencv_legacy.2.4.3.dylib
libopencv_ml.2.4.3.dylib
libopencv_nonfree.2.4.3.dylib
libopencv_objdetect.2.4.3.dylib
libopencv_photo.2.4.3.dylib
libopencv_stitching.2.4.3.dylib
libopencv_ts.2.4.3.dylib
libopencv_video.2.4.3.dylib
libopencv_videostab.2.4.3.dylib
我发现nm
搜索所需的符号没有任何意义,因为名称修饰很难在我的脑海中反编译.我只是蛮力地包括了所有库,但仍然出现链接器错误:
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 main.o
"cv::FeatureDetector::detect(cv::Mat const&, std::__1::vector<cv::KeyPoint, std::__1::allocator<cv::KeyPoint> >&, cv::Mat const&) const", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
从这里开始,我已经对OpenCv参考文档和Wiki页面进行了抽查.
http://opencv.willowgarage.com/documentation/cpp/features2d__feature_detection_and_descriptor_extraction.html
但没有成功.
我将很感激
- 查找这些OpenCv API的特定帮助
- 这种查询的一般策略:哪个库包含我需要链接的符号".这种问题使我讨厌C ++,因为5分钟的编码似乎总是导致数小时的库搜索,这可能是因为我不知道这样做的专业秘密.
我的工具链利用CMake来跟踪这些事情.对于我使用的大多数新库,通常会有由Google随附的由他人编写的Find * .cmake文件.如果您想了解有关我的特定设置的更多信息,请随时询问.对于非自由库中的内容,我已经多次看到这个特定的问题(体系结构x86_64的未定义符号).不过,我不确定为什么您会收到该错误.我首先要看的是samples/cpp文件夹中的matcher_simple.cpp示例.如果您可以编译并运行此程序(使用此)以及其他示例,则可以进行设置应该可以.如果不能,请张贴该示例的错误信息吗?我不熟悉XCode,但建议转到Build Settings> Build Options> C/C ++/Objective-C的编译器,并将其从Apple LLVM编译器更改为LLVM GCC 4.2.在此处还有一些其他猜测.. >
on Mac OSX 10.8, XCode 4.6, in C++
I'm following the tutorial in opencv_tutorials.pdf
, located in /opt/local/share/OpenCV/doc
on my system. On page 311, we get this sample (slightly edited):
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
int main( int argc, char** argv ) {
Mat img_1 = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
int minHessian = 400;
SurfFeatureDetector detector( minHessian );
std::vector<KeyPoint> keypoints_1;
detector.detect( img_1, keypoints_1 );
}
I had to modify the code above to #include "opencv2/nonFree/features2d.hpp"
, a file that I found by running
find /opt/local/include -name "*.hpp" -exec grep SurfFeatureDetector "{}" ';' -print
The code compiles, meaning that the symbol detector.detect
is found in the hpp
file and passes type-checking by the C++ compiler. Next is to try to find the libraries that contain the symbols.
Now, I have these libraries in my distribution, in /opt/local/lib
:
libopencv_calib3d.2.4.3.dylib
libopencv_contrib.2.4.3.dylib
libopencv_core.2.4.3.dylib
libopencv_features2d.2.4.3.dylib
libopencv_flann.2.4.3.dylib
libopencv_gpu.2.4.3.dylib
libopencv_highgui.2.4.3.dylib
libopencv_imgproc.2.4.3.dylib
libopencv_legacy.2.4.3.dylib
libopencv_ml.2.4.3.dylib
libopencv_nonfree.2.4.3.dylib
libopencv_objdetect.2.4.3.dylib
libopencv_photo.2.4.3.dylib
libopencv_stitching.2.4.3.dylib
libopencv_ts.2.4.3.dylib
libopencv_video.2.4.3.dylib
libopencv_videostab.2.4.3.dylib
I found it uninformative to nm
search these for the required symbols because name mangling is difficult to decompile in my head. I just brute-force included all the libraries, but still get linker errors:
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 main.o
"cv::FeatureDetector::detect(cv::Mat const&, std::__1::vector<cv::KeyPoint, std::__1::allocator<cv::KeyPoint> >&, cv::Mat const&) const", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
I've done some spot-checking of the OpenCv reference documents and the wiki pages, starting from here
http://opencv.willowgarage.com/documentation/cpp/features2d__feature_detection_and_descriptor_extraction.html
but without success.
I'd be grateful for
- specific help in finding these OpenCv APIs
- general strategies for this kind of query: "what library contains the symbol I need to link against". This kind of problem makes me hate C++, since 5 minutes of coding always seems to lead to hours of hit-and-miss library searching, possibly because I just don't know the professional secret for doing this.
My toolchain utilizes CMake to keep track of these sorts of things. For most new libraries I use, there are usually google searchable accompanying Find*.cmake files that are written by others. If you wanted more information about my specific set-up, feel free to ask. I have seen this specific problem (Undefined symbols for architecture x86_64) a few times for things in the nonfree libraries. I'm not sure why you are getting that error for the imread, though. The first place I would look is the matcher_simple.cpp example in the samples/cpp folder. If you can compile and run this (using this) and the other examples, your set-up should be ok. If you can't, can you please post the errors of that example? I'm not familiar with XCode but someone else suggested going to Build Settings>Build Options> Compiler for C/C++/Objective-C and change it from Apple LLVM Compiler to LLVM GCC 4.2. And there are a few other guesses here too.
这篇关于OpenCv 2.4.3:找不到读取和SurfFeatureDetector :: detect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!