Building VTK for Mobile Architectures

March 6, 2015

Starting with the 6.2.0 release, VTK now provides support for mobile architectures, specifically iOS and Android. The new OpenGL2 rendering backend supports both OpenGL ES 2.0 and 3.0. VTK’s build system has also been simplified for cross-compiling to mobile architectures.

 

With these changes, VES will soon be deprecated in favor of VTK for all new mobile development. As this support is currently considered beta quality, we encourage contributors to use, extend, and file bugs against VTK for these architectures.

 

The remainder of this post is a guide for building VTK for mobile devices:

 

 

iOS

 

First ensure that you have the latest Xcode and XCode developer tools installed.

 

To build the VTK framework for iOS development, configure CMake with VTK_IOS_BUILD=ON. CMake will then present a limited set of options, which will we shortly review. Be sure to generate only Unix Makefiles or Ninja build files, as Xcode will not work for this special build. Then use CMake as usual to produce project build files.

 

The project files generated by CMake will perform three builds. The first is done to generate VTK’s compile tools which are needed for cross compilation. The second build compiles all supported VTK libraries for the specified device architectures. The last build compiles the same libraries for the specified simulator architectures.

 

Once the three builds have been completed, all built libraries are statically combined into vtk.lib using libtool. This, along with the VTK header files, constitutes vtk.framework which can be used directly in iOS projects.

 

For a starting point, there are several examples in the Examples/iOS directory.

 

The CMake options relevant to most users here are:

 

CMAKE_FRAMEWORK_INSTALL_PREFIX is the directory in which vtk.framework will be installed. This path defaults to /usr/local/frameworks, which is where the examples bundled with VTK will look for the framework.

 

IOS_DEVICE_ARCHITECTURES is the list of device architectures to build. Check the current Xcode documentation to choose the correct architectures for your supported devices.

 

IOS_SIMULATOR_ARCHITECTURES is the list of simulator architectures to build. Typically this is simply i386 or x86_64, i.e., the architecture of your development and/or testing machines.

 

OPENGL_ES_VERSION should be either 2.0 or 3.0.

 

 

Android

 

Update: Please use VTK v6.2.0.rc1 or later as v6.2.0 has a bug that will prevent a successful build.

 

First ensure that you have installed the latest Android NDK (Native Development Kit). As of writing, VTK supports NDK versions 5 through 10d (December 2014).

 

Configure CMake with VTK_ANDROID_BUILD=ON, confirm or change the presented options, then build. Currently only Makefiles and Ninja build files are supported. As with the iOS build process, VTK will be built more than once. For Android only two passes are required, once for the compile tools and a second time to cross-compile to the chosen Android architecture.

 

The built static libraries can then be used in your Android project. Unfortunately as of this writing, there are no examples for Android. We encourage all developers to share and contribute examples when possible.

 

For Android, the relevant CMake options are:

 

ANDROID_NDK specifies the path to the Android NDK. Typically this is /opt/android-ndk on Unix-like systems.

 

ANDROID_ARCH_NAME specifies the target Android architecture for cross compilation.

 

ANDROID_NATIVE_API_LEVEL – The API level to support. For example, Android 5.0 ‘Lollipop’ is API level 21.

 

OPENGL_ES_VERSION should be 2.0 or 3.0.

 

46 comments to Building VTK for Mobile Architectures

  1. Hi,Tim.I build VTK for Android on windows.I have installed Android NDK 10d,VS2010 and CMAKE 3.2.0.

    I use cmake build VTK.The generator is VS2010.I have configured VTK_ANDROID_BUILD=ON.And
    ANDROID_ARCH_NAME=x86.
    ANDROID_NATIVE_API_LEVEL=15.
    OPENGL_ES_VERSION=2.0

    But I come across a few problems.
    I open VTK.sln with VS2010.The project have “ALL_BUILD”,”vtk-android”,”vtk-compile-tools”,”ZERO_CHECK”. I build “ALL_BUILD”.

    ERROR 1:
    Build files have been written to: D:/VTK-6.2.0/bin/CMakeExternals/Build/vtk-compile-tools
    Performing build step for ‘vtk-compile-tools’
    make: *** No rule to make target `vtkCompileTools’. Stop.

    ERROR 2:
    2> Performing configure step for ‘vtk-android’
    2> CMake Error at CMakeLists.txt:28 (project):
    2> CMAKE_SYSTEM_NAME is ‘Android’ but ‘NVIDIA Nsight Tegra Visual Studio
    2> Edition’ is not installed.
    2>
    2>
    2> — Configuring incomplete, errors occurred!
    2> See also “D:/VTK-6.2.0/bin/CMakeExternals/Build/vtk-android/CMakeFiles/CMakeOutput.log”.

    It said “NVIDIA Nsight Tegra Visual Studio Edition is not installed”.I installed it after.But it still has this error.

    That’s all.Thank you very much for your help! 🙂

  2. Hey Arron,

    Visual Studio is not yet a supported generator for this scheme. I apologize for that omission; I’ll edit the post to avoid further confusion.

    However, one possible solution is to use Cygwin. Using its command line interface you can use the CMake scheme outlined above to generate makefiles which can build VTK. The built libraries can then be added to your Visual Studio Android project.

    We’re still working to improve our build support for mobile architectures, so stay tuned.

    If you have any more questions, feel free to send mail to the VES or VTK mailing lists.

    Tim

  3. Hi Tim,

    Just wondered whether Visual Studio was now a supported generator for this scheme or the solution was still to use Cygwin?

    Thanks a lot for the help.

    Best,

    Lonni

  4. Following your IOS instructions i get this error for the vtk Compile tools:

    — Build files have been written to: /Users/Guillaume/Downloads/VTK-6.2.0
    [ 25%] Performing build step for ‘vtk-compile-tools’
    make[3]: *** No rule to make target `vtkCompileTools’. Stop.
    make[2]: *** [CMakeExternals/Prefix/vtk-compile-tools/src/vtk-compile-tools-stamp/vtk-compile-tools-build] Error 2
    make[1]: *** [CMakeFiles/vtk-compile-tools.dir/all] Error 2
    make: *** [all] Error 2

  5. Hey William,

    It isn’t clear to me what your error is just going on that. Just make sure you’re not trying to compile the tools separately; they should be handled by the process I outlined.

    I will investigate in the next day or two and get back to you.

  6. Hello guys,

    I actually get the exact same error.
    Building VTK works just fine, however whenever I want to include support for android I get the same message than you do.

  7. Hey Need and Lonni,

    This build process is just designed to get VTK libs built such that you could use them in your (separate) Android project. It sounds like you’re trying to both build the libs and generate a VS project in the same go — that won’t work. You would need two separate CMake configs for each of these steps (the first is done for you). Does that make sense?

    I know this is far from ideal, but we’re hoping to make further improvements soon.

    Hope that helps,
    Tim

  8. Thanks for this quick answer.

    I’m afraid I don’t really get what you mean. Sorry I’m brand new to this (both Cmake and VTK).

    I have used Cmake just the way you described it in the post up there. I use Visual Studio 2013 as a generator as this is the only one that I have currently.
    Then, when trying to build I get the error that was mentioned above. Is that because Visual Studio is not a supported generator? Or is this something else?

    Thanks for the help 🙂

    Lonni

  9. Yes, for this portion Visual Studio is not a supported generator. Currently, you’d have to do something like the following:

    1. Build VTK for Android using the process I’ve outlined above. Don’t specify a generator in this step, as Visual Studio is not currently supported.

    2. Create a second CMake project that creates a Visual Studio solution for your Android app.

    3. Manually include the binaries and headers you built in step #1 into the project you created in step #2.

    Make sense?

  10. So correct me if I’m wrong, this is all still pretty confusing to me.

    I use CMake GUI in a first run. However, CMake does ask me for a generator. So I’m guessing I can use MinGW.
    The next steps confuse me. Once I’m done running CMake to generate the makefile, don’t I have to actually Make? What about the creation of the second CMake Project? I’ve tried to find some documentation on how to make that but I’ve been to say the least, not successful.

    Sorry to bother you with that many questions

    Best,

    Lonni

  11. Yes, you will have to use MinGW and Makefiles to build VTK for Android.

    For the second step, I’m simply saying that you will need to create a second project into which you can include the built VTK libs. That part is up to you.

  12. Hey Tim Thirion,

    I simply launch the command make -j4 and then get the error i posted above, i checked the folder where it seems to be looking for the vtk-compile-tools-build and that file is missing…

    Thanks

  13. William,

    I just tested the following, starting from a completely clean slate:

    In source directory:
    $ git checkout v6.2.0

    In build directory:
    $ ccmake /path/to/VTK -DVTK_IOS_BUILD=ON
    Configure with defaults and generate
    $ make -j4

    Everything gets build successfully.

    Are you doing some extra steps? Configuring with VTK_IOS_BUILD enabled will take care of building the compile tools for you; you don’t need to explicitly build them.

    TT

    1. Have you successfully created the vtk.framework for ios? Could you give me a copy of your cmake order? Thank you

  14. i followed your steps (i image the cmake step is $ cmake -D VTK_IOS_BUILD=ON /path/to/VTK) and get this error :

    http://pastebin.com/bQ1r2624 (to not spam this section)

    then it keeps going with the build step for ‘vtk-ios-simulator’

    and then :

    [ 87%] Completed ‘vtk-ios-simulator’
    [ 87%] Built target vtk-ios-simulator
    make: *** [all] Error 2

  15. Try running ‘ccmake’ instead of ‘cmake’. It needs to go through several configure steps first before generating the makefiles.

    I’m not seeing the error you’re getting. Are you sure you’re using v6.2.0?

  16. i get this now :

    CMake Error: Error in cmake code at
    /Users/Guillaume/Desktop/VTK/CMake/ios.device.toolchain.cmake:89:
    Parse error. Function missing ending “)”. Instead found unterminated string with text “)”.
    CMake Error at /opt/local/share/cmake-3.2/Modules/CMakeDetermineSystem.cmake:104 (message):
    Could not find toolchain file: CMake/ios.device.toolchain.cmake
    Call Stack (most recent call first):
    CMakeLists.txt:28 (project)

  17. William, can you email that file (ios.device.toolchain.cmake) to me at tim.thirion@kitware.com?

    I will try to help you through it.

    In general, we slightly prefer using the VTK mailing list to help users with issues as you will get a much wider set of developers’ eyes on it there than on a given blog post.

  18. Hello Tim Thirion,

    i built the VTK for iOS successfully thanks to you, but i have a problem when i try to run the volume rendering example it says “vtkOpenGLGPUVolumeRayCastMapper.h” file not found.

    can you please help me with this? Thanks

    1. Have you successfully created the vtk.framework for ios? Could you give me a copy of your cmake order? Thank you

  19. Yassmin,

    Volume rendering is only available if you set the OpenGL ES version to be 3.0. Does it work if you do that?

    TT

  20. Hello Tim,

    Thanks for your reply.
    Yes it does thanks, the files generated when i set OpenGL ES to version 3.0, but the GLPaint example didn’t run as it’s not supported in OPenGL ES 3.0 only 2.0 and for the volume rendering example it has like 157 linker error.

    Thanks an advance.

  21. Hey Yassmin,

    For the VolumeRender example, go into the Build Settings and choose a different C++ Standard Library. I think the libstdc++ should resolve those linker errors.

    For the GLPaint example, open the MyGLKViewController.mm file and change line 129 to use OpenGLES3.

    Those fixes should get you going.

    TT

  22. sorry but just one last question please,

    does the volume rendering run only for device? not for simulator? as while running the code in simulator i has an error say “Debug: Off” does it related to the device/simulator ?

  23. No, it should run on the simulator. I just ran it on the ‘iPhone 6s Plus’ emulator, for example. I haven’t seen the error that you saw.

    TT

  24. the simulator always has those error,

    /Users/Yassmin/desktop/VTKBin/VTK/Rendering/OpenGL2/vtkOpenGLPolyDataMapper2D.cxx, line 850
    vtkOpenGLPolyDataMapper2D (0x7fd3b0f5c9b0): failed after RenderOverlay 1 OpenGL errors detected
    0 : (1286) Unknown error

    ERROR: In /Users/Yassmin/desktop/VTKBin/VTK/Rendering/OpenGL2/vtkTextureObject.cxx, line 554
    vtkTextureObject (0x7fd3b0d3bb20): failed at glBindTexture(0) 1 OpenGL errors detected
    0 : (1286) Unknown error

  25. I haven’t seen these. All I can say is try to use the very latest master branch. I’m on the commit whose hash begins with 0e6916a.

    If you have further issues, I recommend mailing the VTK mailing list: vtk-developers@vtk.org. That way you’ll reach a wider audience who may be able to help you.

    TT

  26. Hi gys

    https://s.mail.ru/7unR/ckL2iVTtQ

    Could you please help me?

    in vtk root i run commands:
    1. cmake -DVTK_IOS_BUILD=ON
    2. make

    after command 2. I have the same error as above
    make[3]: *** No rule to make target `vtkCompileTools’. Stop.
    make[2]: *** [CompileTools/src/vtk-compile-tools-stamp/vtk-compile-tools-build] Error 2
    make[1]: *** [CMakeFiles/vtk-compile-tools.dir/all] Error 2
    make: *** [all] Error 2

    Thanks

  27. CMake Error at CMake/MakeFramework.cmake:11 (message):
    VTK not installed. Build the source then build the ‘install’ target.

  28. I want to use VTK in ios. According to the instructions, I plan to Build the vtk.framework of ios, but it is prompted in make that VTK not installed. Build the source then Build the ‘install’ target。The vtk.framework generated after I manually created the corresponding directory is 0 bytes. Why is this? Thank you。

    Before calling this, ensure that the following variables are set:
    #

    VTK_GLOB_LIBS – a path containing a wildcard suitable for globbing

    VTK_INSTALLED_HEADERS – the path containing all headers for the framework

    Can you elaborate on how to set these two

    1. Thanks for your reply, yes, I completely followed the instructions of this blog, I used make and make install to install VTK, I created build directory in vtk-8.2.0 directory and set CMAKE_FRAMEWORK_INSTALL_PREFIX, IOS_DEVICE_ARCHITECTURES, IOS_SIMULATOR_ARCHITECTURES, OPENGL_ES_VERSION with cmake, An error prompted when watching sudo make-j4 in the build directory after VTK_IOS_BUILD, Configuring and Generate success.looks forward to replying!

      1. Your first build and install of VTK is not necessary. Clone the source, make a build directory, and follow the instructions on this blog post.

        1. Thank you very much for your reply again. Yes, your suggestion is very timely. I have successfully built the framework. Thank you very much!

    2. Through Error CMake Error at CMake/MakeFramework CMake: 11 (the message) :
      VTK not installed. Build the source then Build the ‘install’ target.
      If (NOT the EXISTS “/ Users/shengfeizhang/Desktop/VTK 8.2.0 / VTK – 8.2.0 – build/CMakeExternals/Install/VTK – ios – simulator/include/VTK – 8.2”)
      The message (FATAL_ERROR
      “VTK not installed. Build the source then Build the ‘install’ target.”)
      Endif () if I create this directory manually, the vtk.framework can generate but is 0 bytes. If I copy the VTK installation header file to this directory and set VTK_GLOB_LIBS to /usr/local/lib I can get a vtk.framework. but it is not available

    3. When I was running VTK ios Example PlaneView, I was prompted ‘vtkoutlinefilter. h’ file not found. I found this file contained in VTK source.

Leave a Reply to William Du RoyCancel reply