在XCode 7.0.1中设置VTK 6.1 [英] Setting up VTK 6.1 in XCode 7.0.1

查看:128
本文介绍了在XCode 7.0.1中设置VTK 6.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我遇到了使 VTK(可视化工具包)在Mac OSX上运行的问题,特别是即可在 XCode 中使用.

(我可以使用它,并将在下面发布该问题的答案)

截至2015年10月的当前设置:

  • MacBook Pro 13英寸(2015年初),2.7 GHz i5、8GB内存,Intel Iris 图形6100(1,5GB)
  • OS X El Capitan
  • XCode版本7.0.1
  • VTK版本6.1

解决方案

我希望这将对在OSX上配置和构建VTK以及正确设置XCode以成功构建VTK项目的整个过程有类似问题的所有人有所帮助.我也希望我不会忘记任何相关的东西.如果您有任何疑问或看到我犯的一些错误,请发表评论/回答.

我将逐步完成从构建VTK到设置XCode的整个过程.我做了很多谷歌搜索并尝试了不同的事情.另外,我将尝试提供一些屏幕截图以帮助澄清问题,特别是对于像我这样的XCode新手.据我记得并为它们添加了书签,我还将提供可帮助我进行设置的资源.

下载,构建并构建安装

这主要包括来自该stackoverflow线程的步骤:为支持Cocoa的OSX 10.8安装VTK 6.1

  1. 从Github克隆VTK源到您选择的目录

    cd/用户/您/

    git clone https://github.com/Kitware/VTK.git

    cd VTK

    git checkout标签/v6.1.0

  2. 创建一个构建目录

    mkdir VTKBuild

    cd VTKBuild

    如果您不知道C/C ++上下文中的建筑"是什么意思,建议您做进一步的阅读:

    IF(APPLE)
     SET(VTK_OBJCXX_FLAGS_DEFAULT "-fobjc-gc")
     SET(VTK_REQUIRED_OBJCXX_FLAGS ${VTK_OBJCXX_FLAGS_DEFAULT} CACHE STRING "Extra flags for Objective-C++ compilation")
     MARK_AS_ADVANCED(VTK_REQUIRED_OBJCXX_FLAGS)
    ENDIF()
    

    删除或注释这些行.如果您找不到它们,那么我认为您应该很好,因为它可能在较新的版本中已解决.

    来源:

    如果您按照本教程使用的OS X版本与我不同,则最后一个配置行的值可能会有所不同.在我的CMakeCache.txt中,它已经配置为正确的值.

    其他来源:第一部分:在Mac上构建VTK库

  3. 编译VTK项目

    这可能需要很长时间,您可以通过添加-j( +核心数)参数.这告诉您的编译器使用多个内核来编译文件,并应加快处理速度. (您仍在VTKBuild/目录中.)

    制作

  4. 现在将头文件和库复制到包含目录

    进行安装

    这应该在/VTKBuild目录中创建一个/lib和一个/include目录.我们稍后将参考它们.

    这应该在建筑部分完成. VTK现在已正确安装在您的系统上.

设置XCode项目

来源:第三部分:手动创建Xcode

作为一般建议.如果您配置一些路径,请尝试使用绝对路径.尤其是当我编写".../VTKBuild"之类的内容时,请将"..."替换为路径的正确部分.

  1. 创建一个新项目

    启动XCode并创建一个新项目(文件"->新项目").选择"OS X->应用程序->压线工具".单击下一步",命名,然后选择C ++作为语言".选择所需的位置,然后单击创建".

  2. 添加了必要的框架

    在左侧栏中选择您的项目,然后在中心导航至构建阶段".这应该给您以下视图:

    现在,展开使用库链接二进制文件"行.在一个新项目中,它不应包含任何内容.现在,我们需要链接OpenGL,Cocoa和IOKit框架.您可以通过点击底部的+按钮来执行此操作.这将开启与某些框架的对话.只需搜索上述框架,然后点击添加"即可.

    我们还需要添加zlib库.再次点击+按钮,然后搜索"libz".然后添加"lib.tbd"库.有多个版本可用,我只是添加了一个没有版本号的版本.其他人也可能工作.这是现在的样子:

    现在,我们需要添加 VTK库文件.这些位于您的/VTKBuild/lib目录中.它们应命名为"libvtkXXX.a".您可以将它们拖放到窗口中,也可以像上一步中的框架一样通过文件对话框选择它们:+按钮->'添加其他..'->导航至/VTKBuild/lib->全选* .a具有Shift + Click/Cmd + Click->'打开'的文件.它们可能需要一段时间才能在界面上显示.

  3. 配置源代码树

    打开XCode首选项(CMD +).在顶部栏中,导航到位置",然后选择源树".添加两行:

    名称"-显示名称"-路径"

    vtk-debug-include vtk-debug-include ... VTKBuild/include/vtk-6.1

    vtk-debug-lib vtk-debug-lib ... VTKBuild/lib

  4. 添加搜索路径

    我们现在需要告诉XCode在哪里寻找其他头文件(* .h),以便您能够在代码中"#include< ...>"它们.

    为此,再次在左侧栏中选择您的项目.导航到构建设置",然后输入过滤器搜索".应该有一个名为"Search Paths"的行,其子行为"Header Search Paths"和"Library Search Paths".需要将第一个设置为'... VTKBuild/include/vtk-6.1',将后一个设置为'... VTKBuild/lib'.

  5. 定义宏

    如果您完成以上所有操作.包含VTK标头文件的项目应生成并运行.但是要正确运行,您可能需要在* .cpp文件之上定义两个宏,然后再执行任何#include语句:

    #define vtkRenderingCore_AUTOINIT 4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingFreeTypeOpenGL,vtkRenderingOpenGL)
    #define vtkRenderingVolume_AUTOINIT 1(vtkRenderingVolumeOpenGL)
    

    没有这些,例如vtkWindowInteractor无法正常工作.

就是这样!有趣的可视化内容.

So, I ran into the problem of getting VTK (Visualization ToolKit) to work on Mac OSX, especially getting it to work in XCode.

(I got it to work and will post the answer to this question below)

Current setup as of October 2015:

  • MacBook Pro 13" (Early 2015) 2,7 GHz i5, 8GB Memory, Intel Iris Graphics 6100 (1,5GB)
  • OS X El Capitan
  • XCode Version 7.0.1
  • VTK Version 6.1

解决方案

I hope this will help everyone having similiar problems with the whole process of configuring and building VTK on OSX and setting up XCode correctly to successfully build VTK projects. Also I hope that I won´t forget anything relevant. If you have questions or see some errors I made, please comment/answer.

I will go through the whole process from building VTK to setting up XCode step by step. I did A LOT of googling and trying out different things. Also I will try to provide some screenshots to help clarify things, especially for people new to XCode, like me. As far as I remember and bookmarked them, I will provide the sources helping me with setup, too.

Download, Build & Install

This will mostly include steps from this stackoverflow thread: Installing VTK 6.1 for OSX 10.8 with Cocoa support

  1. Clone VTK sources from Github to a directory of your choice

    cd /Users/you/

    git clone https://github.com/Kitware/VTK.git

    cd VTK

    git checkout tags/v6.1.0

  2. Make a build directory

    mkdir VTKBuild

    cd VTKBuild

    If you have no idea what "building" means in a context of C/C++, I suggest you do some further reading: Building C/C++: what really happens and why does it take so long

  3. Editing the CMakeLists.txt

    In your downloaded sources directory (not the /VTKBuild directory), there should be a file "CMakeLists.txt". Open it up in a text editor and search for the lines:

    IF(APPLE)
     SET(VTK_OBJCXX_FLAGS_DEFAULT "-fobjc-gc")
     SET(VTK_REQUIRED_OBJCXX_FLAGS ${VTK_OBJCXX_FLAGS_DEFAULT} CACHE STRING "Extra flags for Objective-C++ compilation")
     MARK_AS_ADVANCED(VTK_REQUIRED_OBJCXX_FLAGS)
    ENDIF()
    

    Delete or comment these lines. If you don´t find them to begin with, I think you should be good to go, as this may be fixed in newer versions.

    Source: [Solved] Build Qt 5.2.1 + VTK 6.1.0 + CMake 2.8.12.2

  4. Run cmake script

    Change in your /VTKBuild directory. You are now inside /Users/you/VTK/VTKBuild

    cmake ..

  5. Edit CMakeCache.txt

    Now we need to edit a few lines in the generated CMakeCache.txt (in your /VTKBuild directory).

    CMAKE_INSTALL_PREFIX. So make sure to use "/Users/you/" instead of "~":
    
    CMAKE_INSTALL_PREFIX:PATH=/Users/you/VTK/VTKBuild
    
    BUILD_SHARED_LIBS:BOOL=OFF
    
    CMAKE_BUILD_TYPE:STRING=Debug
    
    VTK_USE_SYSTEM_ZLIB:BOOL=ON
    
    CMAKE_OSX_ARCHITECTURES:STRING=i386;x86_64
    
    VTK_USE_COCOA:BOOL=ON
    
    VTK_USE_CARBON:BOOL=OFF
    
    CMAKE_OSX_SYSROOT:STRING=/Applications/XCode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk
    

    The value of the last config line may vary if you follow this tutorial having a different OS X version than me. In my CMakeCache.txt it was already configured to the correct value.

    Additional Sources: Part One: Build VTK libraries on Mac

  6. Compile the VTK project

    This may take long, you can accelerate the process by adding the -j ( +number of cores) parameter. This tells your compiler to use more than one core to compile the files and should speed things up. (You are still in the VTKBuild/ directory).

    make

  7. Now copy the header files and libraries to an include directory

    make install

    This should create a /lib and a /include directory in your /VTKBuild directory. We will later reference to them.

    This should do it for the building part. VTK is now correctly installed on your system.

Setting up the XCode project

Source: Part Three: Create Xcode by hand

As a general advise. If you configure some paths, try to use absolute paths. Especially when I write something like '.../VTKBuild', replace '...' with the correct part of the path.

  1. Create a new project

    Launch XCode and create a new project (File -> New Project). Choose OS X -> Application -> Comand Line Tool. Click 'Next', name it, and select C++ as your 'Language'. Choose a location of your desire and finish with 'Create'.

  2. Added necessary frameworks

    Select your project in the left bar, then in the center navigate to 'Build Phases'. This should give you this view:

    Now expand the 'Link Binary with Libraries' row. On a fresh project this should´t contain anything. We now need to link the OpenGL, Cocoa und IOKit frameworks. You do this by hitting the + button on the bottom. This will open a dialogue with some frameworks. Just search for the aformentioned frameworks and hit 'Add'.

    Also we need to add the zlib library. Again hit the + button, and search for 'libz'. Then add the 'lib.tbd' library. There a multiple versions available, I just added the one without a version number. Others may work as well. This is what it should look like by now:

    Now we need to add the VTK library files. These are located in your /VTKBuild/lib directory. They should be named something like 'libvtkXXX.a'. You can either just drag&drop them into the window or select them, like the frameworks on the above step, via the file dialogue: + button -> 'Add Other..' -> Navigate to /VTKBuild/lib -> select all *.a files with Shift+Click/Cmd+Click -> 'Open'. It may take a while until they show up on the interface.

  3. Configure Source Tree

    Open the XCode Preferences (CMD+,). In the top bar navigate to 'Locations' and select 'Source Trees'. Add two rows:

    "Name" - "Display-Name" - "Path"

    vtk-debug-include vtk-debug-include ...VTKBuild/include/vtk-6.1

    vtk-debug-lib vtk-debug-lib ...VTKBuild/lib

  4. Add search paths

    We now need to tell XCode where to look for additional header files (*.h), in order for you to be able to '#include <...>' them in your code.

    For this, again, select your project on the left bar. Navigate to 'Build Setting' and type in the Filter 'search'. There should be a row named 'Search Paths' with sub-rows 'Header Search Paths' and 'Library Search Paths'. The first one needs to be set to '...VTKBuild/include/vtk-6.1', the latter one to '...VTKBuild/lib'.

  5. Define Macros

    If you done everything of the above. A project which includes VTK Header files should build and run. But to run correctly, you may need to define two macros on top of your *.cpp files, BEFORE any #include statements:

    #define vtkRenderingCore_AUTOINIT 4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingFreeTypeOpenGL,vtkRenderingOpenGL)
    #define vtkRenderingVolume_AUTOINIT 1(vtkRenderingVolumeOpenGL)
    

    Without these I e.g. had problems with the vtkWindowInteractor not working.

That´s it! Have fun visualizing stuff.

这篇关于在XCode 7.0.1中设置VTK 6.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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