OpenCV with xcode error: Undefined symbols for architecture x86_64:

社会主义新天地 提交于 2019-12-22 10:25:02

问题


I'm trying to install opencv and use it with xCode for making application in C++. I installed it using macports and follow many tutorials to do it. I have done the linking too in xcode but there is problems that some function dosen't work. it give an error like 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)

If I switch the build arch to 32 bits, it gives the same error with more functions.

any idea ? I try to delete macports with opencv and install it using homebrew in 32 bits build but homebrew cannot install it for unknown error. so is the library not 64 bits compatible ?


回答1:


I got OpenCV 2.3.0 installed on my Mac through my favorite way, which is download the source code and compile it:

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

Then:

make
sudo make install

And there it is:

$ 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

Note: if you need to install any dependencies, use brew!

And all OpenCV libs are 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

I suggest you remove the current OpenCV installation and make sure there is nothing left in your system before downloading and compiling it from scratch.



来源:https://stackoverflow.com/questions/8494279/opencv-with-xcode-error-undefined-symbols-for-architecture-x86-64

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!