Cross-compiling for iOS


#1

Hello. I am looking for a way to cross-compile HDF5 for iOS (arm64 architecture). Trying to build by using CMake does not give the output I was looking for. There are a lot of checks and tests performed, but it doesn’t seem to be testing for the host platform (iOS), but rather for the build platform? Which is macOS x86_64 here.

This is the command I used. Note that I was able to cross-compile zlib and szip separately successful:

cmake -DCMAKE_INSTALL_PREFIX="/Users/development/Desktop/HDF/hdf-ios-output" \
-DHDF5_USE_16_API_DEFAULT="yes" \
-DHDF5_ENABLE_SZIP_SUPPORT="yes" \
-DSZIP_INCLUDE_DIR="/Users/development/Desktop/HDF/hdf-dependencies/szip/szip-ios-output/usr/local/include" \
-DSZIP_LIBRARY_RELEASE="/Users/development/Desktop/HDF/hdf-dependencies/szip/szip-ios-output/usr/local/lib/libszip-static.a" \
-DHDF5_ENABLE_Z_LIB_SUPPORT="yes" \
-DZLIB_INCLUDE_DIR="/Users/development/Desktop/HDF/hdf-dependencies/zlib/output/usr/local/include" \
-DZLIB_LIBRARY_RELEASE="/Users/development/Desktop/HDF/hdf-dependencies/zlib/output/usr/local/lib/libz.a" \
-DCMAKE_CXX_FLAGS='--stdlib=libc++ -fPIC' \
-DCMAKE_OSX_ARCHITECTURES="arm64" \
-DCMAKE_OSX_DEPLOYMENT_TARGET="15.4" \
-DCMAKE_OSX_SYSROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk" \
-DBUILD_TESTING=OFF \
-DHDF5_USE_PREGEN=ON \
-DHDF5_BATCH_H5DETECT=ON -Wno-dev \
-G "Unix Makefiles" ..

There is a lot of output in the CMakeError.log where the symbols are not found for the architecture I am specifying, example:

Determining if the variable CLOCK_MONOTONIC exists failed with the following output:
Change Dir: /Users/development/Desktop/HDF/cmake/CMake-hdf5-1.12.1/hdf5-1.12.1/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_46f96/fast && /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/cmTC_46f96.dir/build.make CMakeFiles/cmTC_46f96.dir/build
Building C object CMakeFiles/cmTC_46f96.dir/CheckVariableExists.c.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc   -DCHECK_VARIABLE_EXISTS=CLOCK_MONOTONIC -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk -miphoneos-version-min=15.4   -o CMakeFiles/cmTC_46f96.dir/CheckVariableExists.c.o   -c /usr/local/Cellar/cmake/3.15.0/share/cmake/Modules/CheckVariableExists.c
Linking C executable cmTC_46f96
/usr/local/Cellar/cmake/3.15.0/bin/cmake -E cmake_link_script CMakeFiles/cmTC_46f96.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc  -DCHECK_VARIABLE_EXISTS=CLOCK_MONOTONIC -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk -miphoneos-version-min=15.4 -Wl,-search_paths_first -Wl,-headerpad_max_install_names   CMakeFiles/cmTC_46f96.dir/CheckVariableExists.c.o  -o cmTC_46f96 
Undefined symbols for architecture arm64:
  "_CLOCK_MONOTONIC", referenced from:
      _main in CheckVariableExists.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [cmTC_46f96] Error 1
make: *** [cmTC_46f96/fast] Error 2

So my main question is; is there currently any known process or workaround for cross-compiling the HDF5 library for the iOS platform?

Thanks for your help!