iOS framework

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

2 Likes

@ken-martin

Hi there Leon,
Did you find a solution to this issue? I’m running into the same thing (compiling tag v8.2.0).
Max

@agirault any advice?

I haven’t tested since 8579c7f which is a while back (March 2017) but it might still work: it relies on using the vtkiOS.cmake script which will leverage the toolchain files in the CMake folder (ios.device.toolchain.cmake.in and ios.simulator.toochain.cmake.in), as well as a script to merge the libraries into one using lipo (MakeFramework.cmake.in).

To configure using those scripts and toolchains, you need to pass -DVTK_IOS_BUILD=1 the first time you call cmake (can’t be from an existing cmake configured project), then set IOS_DEPLOYMENT_TARGET , IOS_DEVICE_ARCHITECTURES , IOS_SIMULATOR_ARCHITECTURES and IOS_EMBED_BITCODE . On top of being ~2y old, it is very verbose since you need to explicitly pass all the modules you need to build, and they’re not all exposed at the moment (see here).

If this doesn’t work out of the box, I would probably try to use the native iOS cross-compilation support instead, which was added to CMake 3.14 here (fat libs only with XCode) and improved recently here (fat libs for ninja+makefile as well)… That would be new for VTK so you might hit some roadblocks as well, but it’s probably the best route to explore.

Edit: I only looked at VTK_GLOB_LIBS and VTK_INSTALLED_HEADERS afterwards and realized they were part of vtkiOS.cmake, which you’re clearly already using. The solutions are then either to fix that script which probably isn’t up to date (don’t we have nightly buidls that would have picked it up @ben.boeckel @ken-martin ?) or to look at the CMake native toolchains instead.

Thanks Alex for the answer.
Compilation and installation worked like a charm finally!
I had to run ccmake with -DVTK_IOS_BUILD=ON (not sure if the problem came from running cmake-gui when I first posted my question).
BTW, no need to call make install. After building the project, the vtk.framework is installed in CMAKE_FRAMEWORK_INSTALL_PREFIX.

1 Like

Great to hear that it still works!

I had to run ccmake with -DVTK_IOS_BUILD=ON

Yes, when you cross-compile you need to use a different toolchain from the get-go, so you need to let CMake know before it really configures anything/runs at all. This is true for the current custom solution in VTK, as well as the newer native CMake solution where you’d need to pass -DCMAKE_SYSTEM_NAME=iOS the first time you call CMake.

Not sure if the problem came from running cmake-gui when I first posted my question

I actually don’t know how to set variables before running CMake with cmake-gui :man_shrugging:.

BTW, no need to call make install . After building the project, the vtk.framework is installed in CMAKE_FRAMEWORK_INSTALL_PREFIX .

Right, and just FYI that’s because of the custom CMake script, in VTK but you would need to if we used the iOS toolchain from CMake instead.


Have fun with it, and if you make any cool progress you can share with us please do so!

1 Like

Thank you Alex for following up.
If someone’s looking at this thread and trying to compile an iOS example from the Examples folder of VTK, here are the steps that worked for me (I’m currently using Xcode 10.3):

  • sudo cp -r <CMAKE_FRAMEWORK_INSTALL_PREFIX>/vtk.framework /Library/Frameworks/ (this is only necessary if the <CMAKE_FRAMEWORK_INSTALL_PREFIX> is not a standard framework path otherwise you need to explicitly set is in Xcode)
  • open <source_folder_path>/Examples/iOS/Surfaces (or any other VTK example in the iOS folder) #NOTE: some examples may need non-default specific VTK modules to be built in the framework building step.
  • add the following 2 lines to the .plist file (this is because the VTK examples are not up-to-date?):
    • <key>CFBundleShortVersionString</key>
    • <string>1.0.0</string>
  • because Xcode10 and higher does not support libstd++ anymore you need to do the following:
    • git clone https://github.com/Kila2/libstdc-.6.0.9.tbd.git <libstd_path>
    • cp <libstd_path>/iPhoneOS/* /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/
    • cp <libstd_path>/iPhoneSimulator/libstdc++.*.dylib /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/
    • cp <libstd_path>/iPhoneSimulator/libstdc++*.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/
  • open <source_folder_path>/Examples/IOS/Surfaces/Surfaces.xcodeproj in Xcode
  • build and run
    Hope this will be useful!

This directory under /Applications/Xcode.app doesn’t seem to exist. I also find it odd you are placing stuff for the simulator in a non-simulator folder. Can you confirm that second step?

This path is for Xcode10, you may be using different version?
To be honset I blindly applied the instruction given in the github link. However, others use the iPhoneSimulator path here but I cannot confirm which works and which does not (so maybe that copy is not necessary at the end?)

I would absolutely love for someone to write up up-to-date instructions with the latest Xcode. I tried it (I tried both putting libstdc++ in Xcode as well as just referencing it in the project), but keeping getting a “‘locale’ file not found” error when compiling. Something in the vtk framework (specifically Headers/vtkdiy2/include/vtkdiy2/fmt/locale.h) is trying to #include <locale> and the system can’t find it.

According to what I’ve read, Xcode support for libstdc++ was deprecated years ago, and you should use libc++ instead. What are the odds of getting things update to use that library instead? I have no idea how different they are, but at least from Apple’s point of view, libstdc++ is past its prime.