Building VTK for Mobile Architectures

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.

 

33 Responses to Building VTK for Mobile Architectures

  1. Arron Guo says:

    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. Tim Thirion says:

    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. Lonni Besançon says:

    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. Tim Thirion says:

    Hey Lonni,

    At this time, only the command line is supported.

    Tim

  5. Lonni Besançon says:

    Alright thanks a lot.

  6. William Du Roy says:

    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

  7. Tim Thirion says:

    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.

  8. Lonni Besançon says:

    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.

  9. Tim Thirion says:

    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

  10. Lonni Besançon says:

    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

  11. Tim Thirion says:

    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?

  12. Lonni Besançon says:

    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

  13. Tim Thirion says:

    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.

  14. William Du Roy says:

    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

  15. Tim Thirion says:

    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

  16. William Du Roy says:

    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

  17. Tim Thirion says:

    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?

  18. William Du Roy says:

    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)

  19. Tim Thirion says:

    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.

  20. Yassmin Abdallah says:

    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

  21. Tim Thirion says:

    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

  22. Yassmin Abdallah says:

    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.

  23. Tim Thirion says:

    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

  24. Yassmin Abdallah says:

    Hello Tim,

    Thanks ALOT that work successfully with me.

    Thanks for your help and time

  25. Yassmin Abdallah says:

    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 ?

  26. Tim Thirion says:

    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

  27. Yassmin Abdallah says:

    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

  28. Tim Thirion says:

    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

  29. occularis says:

    I’m trying to compile VTK 7.1.0 for iOS, as per the instructions here, and it’s failing.

    More details at https://stackoverflow.com/questions/41001334/missing-opengl-extension-items-when-compiling-vtk-for-ios if anyone has any ideas!

  30. Hi! I’ve been able to build VTK 6.2.0 with OpenGL 3.0 support, but the install script fails on vtk-ios-device target. Any idea why?
    Here the output: https://gist.github.com/che1404/ee55cd9f8caf75deca8f5f1f8a330041

    Thanks,
    Robert.

  31. Tim Thirion says:

    I don’t see any specific reason for failure. Can you try VTK 6.3 or 7.0?

  32. Andrei says:

    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

  33. Tim Thirion says:

    Hi Andrei,

    Can you try to build outside of the VTK source directory?

Questions or comments are always welcome!