【问题标题】:OpenCV with xcode error: Undefined symbols for architecture x86_64:带有 xcode 错误的 OpenCV:架构 x86_64 的未定义符号:
【发布时间】:2012-01-19 15:00:31
【问题描述】:

我正在尝试安装 opencv 并将其与 xCode 一起用于在 C++ 中制作应用程序。 我使用 macports 安装了它,并按照许多教程进行操作。我也在 xcode 中完成了链接,但存在某些功能不起作用的问题。它给出了一个错误,例如架构 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 位,它会给出相同的错误,但功能更多。

有什么想法吗?我尝试使用 opencv 删除 macports 并使用 homebrew 在 32 位构建中安装它,但 homebrew 无法安装它,因为未知错误。那么库不兼容 64 位吗?

【问题讨论】:

    标签: c++ xcode macos opencv 64-bit


    【解决方案1】:

    我通过我最喜欢的方式在我的 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 错误,请阅读 this post。无论如何,此时您应该尝试手动(在命令行上)编译任何 OpenCV 应用程序,而不使用 XCode。这将帮助您确定问题是在 XCode 中还是在安装的库中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2015-03-01
    • 2013-04-11
    • 2021-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多