OpenCV在xcode中出现错误:未定义的符号架构x86_64:

3

我正在尝试安装OpenCV并在xCode中使用它来制作C++应用程序。我使用MacPorts进行安装,并遵循了许多教程来完成安装。我已经在xCode中进行了链接,但是出现了一些问题,一些函数无法正常工作。它会给出一个错误,如Undefined symbols for architecture x86_64:

cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)", 
"cv::floodFill(cv::_OutputArray const&, cv::Point_<int>, cv::Scalar_<double>, cv::Rect_<int>*, cv::Scalar_<double>, cv::Scalar_<double>, int)

如果我将构建架构切换为32位,则会出现更多函数的相同错误。
有什么想法吗? 我尝试使用Homebrew在32位构建中删除带有OpenCV的MacPorts并安装它,但Homebrew由于未知错误无法安装它。 所以这个库不支持64位吗?
1个回答

2

我通过我最喜欢的方式在我的Mac上安装了OpenCV 2.3.0,即下载源代码并编译:

tar -xzvf OpenCV-2.3.0.tar.bz2
cd OpenCV-2.3.0
mkdir build
cd build
cmake ../

-- Extracting svn version, please wait...
-- SVNVERSION: 
-- Detected version of GNU GCC: 42 (402)
-- checking for module 'libdc1394-2'
--   package 'libdc1394-2' not found
-- checking for module 'libdc1394'
--   package 'libdc1394' not found
-- Found ZLIB: /usr/lib/libz.dylib (found version "1.2.3")
-- Found PythonInterp: /usr/bin/python2.6 (found version "2.6.1")
--     Use NumPy headers from: /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy/core/include
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named sphinx
-- CUDA detected: 4.0
-- CUDA NVCC target flags: -gencode;arch=compute_11,code=sm_11;-gencode;arch=compute_12,code=sm_12;-gencode;arch=compute_13,code=sm_13;-gencode;arch=compute_20,code=sm_20;-gencode;arch=compute_20,code=sm_21;-gencode;arch=compute_20,code=compute_20
-- Parsing 'cvconfig.h.cmake'
-- 
-- General configuration for opencv 2.3.0 =====================================
-- 
--     Built as dynamic libs?:     ON
--     Compiler:                   
--     C++ flags (Release):        -m32  -Wall -pthread -march=i386  -O3 -DNDEBUG  -fomit-frame-pointer -ffast-math -msse -msse2 -DNDEBUG 
--     C++ flags (Debug):          -m32  -Wall -pthread -march=i386  -g  -O0 -DDEBUG -D_DEBUG -ggdb3 
--     Linker flags (Release):      
--     Linker flags (Debug):        
-- 
--   GUI: 
--     Cocoa:                      YES
-- 
--   Media I/O: 
--     ZLib:                       TRUE
--     JPEG:                       TRUE
--     PNG:                        TRUE
--     TIFF:                       TRUE
--     JPEG 2000:                  TRUE
--     OpenEXR:                    NO
--     OpenNI:                     FALSE
-- 
--   Video I/O:                    QTKit
-- 
--   Interfaces: 
--     Python:                     ON
--     Python interpreter:         /usr/bin/python2.6
--     Python numpy:               YES
--     Use IPP:                    NO
--     Use TBB:                    NO
--     Use ThreadingFramework:     NO
--     Use Cuda:                   YES
--     Use Eigen:                  NO
-- 
--   Documentation: 
--     Build Documentation:        NO
-- 
--     Install path:               /usr/local
-- 
--     cvconfig.h is in:           /Users/karlphillip/installers/OpenCV-2.3.0/build
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/karlphillip/installers/OpenCV-2.3.0/build

然后:

make
sudo make install

这就是它:

$ pkg-config --cflags --libs opencv
-I/usr/local/include/opencv -I/usr/local/include  -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann

注意:如果需要安装任何依赖项,请使用brew
所有的OpenCV库都是x86_64架构的:
$ file /usr/local/lib/libopencv_highgui.dylib 
/usr/local/lib/libopencv_highgui.dylib: Mach-O 64-bit dynamically linked shared library x86_64

$ file /usr/local/lib/libopencv_imgproc.dylib 
/usr/local/lib/libopencv_imgproc.dylib: Mach-O 64-bit dynamically linked shared library x86_64

我建议您删除当前的OpenCV安装,并确保在从头开始下载和编译之前系统中没有任何残留。

@JesseB 要解决你遇到的pkg-config错误,请阅读这篇文章。无论如何,在这一点上,你应该尝试手动编译任何OpenCV应用程序(在命令行上),而不使用XCode。这将帮助你确定问题是在XCode中还是安装的库中。 - karlphillip

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接