在Xcode的64位Mac上编译opencv 2.4 [英] compiling opencv 2.4 on a 64 bit mac in Xcode

查看:101
本文介绍了在Xcode的64位Mac上编译opencv 2.4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我正在ubuntu 12.04下开发的opencv项目,该项目是在具有x86_64架构的Mac上的Parellels VM上进行的.我认为有许多屏幕切换性能问题是由于VM引起的,在Linux视频模式下翻转几秒钟,而opencv应用程序则可以进行摄像头访问.我决定将项目移到计算机Mac端的Xcode中,以继续进行opencv开发.但是,我对xcode不太熟悉,并且无法使项目在此处正确构建.

I have an opencv project that I've been developing under ubuntu 12.04, on a parellels VM on a mac which has an x86_64 architecture. There have been many screen switching performance issues that I believe are due to the VM, where linux video modes flip around for a couple seconds while camera access is made by the opencv application. I decided to moved the project into Xcode on the mac side of the computer to continue the opencv development. However, I'm not that familiar with xcode and am having trouble getting the project to build correctly there.

我已经安装了xcode. 我从Mac上下载并解压缩了最新版本的opencv,然后按照Willowgarage和其他位置的说明运行了〜/src/opencv/build/cmake-gui -G Xcode .. 这似乎工作正常(但是我现在想知道我是否想念这里的体系结构设置,尽管它是Xcode中的64位intel). 然后,我使用来自Linux项目的源文件设置一个xcode项目,并将include目录更改为使用/opt/local/include/...而不是/usr/local/include/.... 我在项目的构建设置中切换了xcode以使用LLVM GCC编译器 然后将C ++的Apple LLVM对话框设置为Language Dialect到GNU ++ 11(这似乎与上面的行不一致)

I have xcode installed. I downloaded and decompressed the latest version of opencv on the mac, and ran: ~/src/opencv/build/cmake-gui -G Xcode .. per the instructions from willowgarage and various other locations. This appeared to work fine (however I'm wondering now if I'm missing an architecture setting in here, although it is 64-bit intel in Xcode). I then setup an xcode project with the source files from the linux project and changed the include directories to use /opt/local/include/... rather than the /usr/local/include/... I switched xcode to use the LLVM GCC compiler in the build settings for the project then set the Apple LLVM Dialog for C++ to Language Dialect to GNU++11 (which seems possibly inconsistant with the line above)

我没有在xcode中使用makefile((我知道-它具有自己的项目文件...)

I'm not using a makefile in xcode, (that I'm aware of - it has its own project file...)

我还遇到了一个链接器问题,看来可以通过添加此链接器标志来解决它们:

I was also running into a linker issue that looked like they may be resolved with the addition of this linker flag:

   -lopencv_video  

基于此处类似的帖子:其他线程 但是,在这种情况下,该人在他们的项目中使用了Makefile.

based on a similar posting here: other thread however in that case the person was using a Makefile in their project.

我尝试在xcode构建设置的其他链接器标志"下添加此链接器标志,但仍然会遇到构建错误.
我认为这里可能有两个问题,一个是使用Cmake构建opencv库时的体系结构设置,另一个是我项目中的链接器标志设置.

I've tried adding this linker flag under "Other Linker Flags" in xcode build settings but still get build errors.
I think I may have two issues here, one with the architecture settings when building the opencv libraries with Cmake, and one with the linker flag settings in my project.

当前的构建错误列表如下:

Currently the build error list looks like this:

    Undefined symbols for architecture x86_64:
    "cv::_InputArray::_InputArray(cv::Mat const&)", referenced from:
    _main in main.o
    "cv::_OutputArray::_OutputArray(cv::Mat&)", referenced from:
    _main in main.o
    "cv::Mat::deallocate()", referenced from:
    cv::Mat::release()    in main.o
    "cv::Mat::copySize(cv::Mat const&)", referenced from:
    cv::Mat::Mat(cv::Mat const&)in main.o
    cv::Mat::operator=(cv::Mat const&)in main.o
    "cv::Mat::Mat(_IplImage const*, bool)", referenced from:
    _main in main.o
   "cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
   _main in main.o
   ---SNIP---
   ld: symbol(s) not found for architecture x86_64
   collect2: ld returned 1 exit status

任何人都可以就下一步尝试提供一些指导吗?

Can anyone provide some guidance on what to try next?

谢谢, 沃尔特

推荐答案

在带有cmake 2.8.10和xcode 4.6.1的mac os x lion 10.7.5上编译和运行c ++ opencv 2.4.4的步骤 在Mac OS X Mountain Lion 10.8.3和Xcode 4.5上使用opencv 2.4.5成功测试了

steps to compile and run c++ opencv 2.4.4 on mac os x lion 10.7.5 with cmake 2.8.10 and xcode 4.6.1 successfully tested with opencv 2.4.5 on mac os x mountain lion 10.8.3 and Xcode 4.5

拥有正确的工具

  1. http://sourceforge.net/projects/opencvlibrary/files/下载opencv-unix并将其解压缩任何地方
  2. http://www.cmake.org/cmake/resources/software.html 并安装
  3. 我假设您在os x lion上拥有xcode 4.6,其中包括ios sdk 6.1
  4. 转到xcode首选项以下载并安装命令行工具,以便拥有g ++等.
  1. download opencv-unix from http://sourceforge.net/projects/opencvlibrary/files/ and untar it wherever
  2. download cmake .dmg from http://www.cmake.org/cmake/resources/software.html and install it
  3. i am assuming you have xcode 4.6 on os x lion which includes the ios sdk 6.1
  4. go to xcode preferences to download and install the Command Line Tools so you have g++ etc.

使用cmake编译opencv

  1. 转到解压缩的opencv文件夹
  2. 创建构建目录

  1. go to the extracted opencv folder
  2. create a build directory

mkdir build
cd build
cmake -D WITH_TBB=OFF -D BUILD_NEW_PYTHON_SUPPORT=OFF -D BUILD_FAT_JAVA_LIB=OFF -D BUILD_TBB=OFF -D BUILD_EXAMPLES=ON -D CMAKE_CXX_COMPILER=g++ CMAKE_CC_COMPILER=gcc -D CMAKE_OSX_ARCHITECTURES=x86_64 -D BUILD_opencv_java=OFF -G "Unix Makefiles" ..
make -j8
sudo make install

  • 从build文件夹转到bin/并运行其中一项测试

  • from the build folder, go to bin/ and run one of the tests

    ./opencv-test-photo
    

  • 创建自己的c ++ opencv xcode项目

    1. 启动xcode并创建一个新的xcode项目
    2. 为os x下的项目类型选择命令行工具
    3. 打开项目的构建设置
    4. 在体系结构"下,将体系结构"设置为64位Intel.还将有效架构设置为x86_64
    5. 在构建选项"下,将"C/C ++编译器"设置为默认编译器"
    6. 在搜索路径"下,将标题搜索路径"设置为/usr/local/include
    7. 也在搜索路径"下,将库搜索路径"设置为/usr/local/lib
    8. 在Apple LLVM编译器4.2下-语言将C ++标准库设置为libstd ++(对于OpenCV 2.4.6,Xcode 5,LLVM 5.0和10.8.5,将语言方言和标准库都设置为编译器默认") li>
    1. fire up xcode and create a new xcode project
    2. select Command Line Tool for the type of project under os x
    3. open your project's build settings
    4. under Architectures, set Architecture to 64-bit intel. also set Valid Architectures to x86_64
    5. under Build Options, set Compiler for C/C++ to Default Compiler
    6. under Search Paths, set Header Search Paths to /usr/local/include
    7. also under Search Paths, set Library Search Paths to /usr/local/lib
    8. under Apple LLVM compiler 4.2 - Language set C++ Standard Library to libstd++ (With OpenCV 2.4.6, Xcode 5, LLVM 5.0, and 10.8.5, set both language dialect and std library to "Compiler Default" instead)

    将已编译的opencv库添加到您的项目中

    1. 转到您所在的构建设置"标签旁边的构建阶段"标签
    2. 在带库的二进制链接"中,单击+号,然后选择添加其他"
    3. 在键盘上按斜杠/并输入/usr/local/lib
    4. 按Enter键并选择要在项目中使用的库
    5. 确保始终选择libopencv_core.2.4.4.dylib
    6. 按Enter键,您将在项目下看到选定的dylib

    编写一些代码

    1. 首先让我们整理文件,右键单击您的项目蓝图图标,然后选择新建组"
    2. 将新组命名为opencv或其他名称
    3. 将测力计拖放到该组中
    4. 打开main.cpp
    5. 从opencv随附的任何示例测试中复制代码,并将其粘贴到此处
    6. 确保已添加所有必需的dylib,例如,如果将opencv_test_stitching.cpp代码复制到main.cpp中,则需要在前面的步骤中添加以下库

    1. first lets organize the files, right click on your project blueprint icon and select New Group
    2. name the new group opencv or whatever
    3. drag the dylibs and drop them in that group
    4. open main.cpp
    5. copy code from any of the sample tests that came with opencv and paste it here
    6. make sure all the required dylibs are added, for example, if you copied the opencv_test_stitching.cpp code into main.cpp, you will need to add the following libraries in the previous steps

    • libopencv_core.2.4.4.dylib
    • libopencv_highgui.2.4.4.dylib
    • libopencv_stitching.2.4.4.dylib

    干杯.

    这篇关于在Xcode的64位Mac上编译opencv 2.4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆