To investigate if and how ITK (later VTK, and sometime, maybe, in the distant future, Slicer) can be compiled an run on a mobile phone. Especially interesting is Samung’s DeX mode, with a desktop like experience.
After setting up the software and the environment variables, the build was done on a freshly installed Debian 12. Only cmake was installed from a repo-
Several problems were encountered:
-D_libcxx_run_result=0 \
-D_libcxx_run_result__TRYRUN_OUTPUT="" \
to the configure line.
ld.lld: error: version script assignment of 'ZLIB_1.2.0' to symbol 'compressBound' failed: symbol not defined
It is fixed by:
-DITK_USE_SYSTEM_ZLIB=ON
export ANDROID_NDK_HOME=/home/attila/Android/Sdk/ndk/28.0.12916984
export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64
export TARGET=aarch64-linux-android
export API=21 # Adjust API level as needed
export AR=$TOOLCHAIN/bin/llvm-ar
export AS=$TOOLCHAIN/bin/llvm-as
export CC=$TOOLCHAIN/bin/$TARGET$API-clang
export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
export LD=$TOOLCHAIN/bin/ld
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
export STRIP=$TOOLCHAIN/bin/llvm-strip
./configure --host=$TARGET --prefix=$PWD/android-build --disable-static --enable-shared
The built iconv of course had to be set in the cmake configure stage:
-DGDCM_USE_SYSTEM_ICONV=ON \
-DCMAKE_C_FLAGS:STRING="-I/home/attila/libiconv-1.18/android-build/include -Dfar=far_nifti" \
-DCMAKE_CXX_FLAGS:STRING="-Dfar=far_nifti" \
-DCMAKE_EXE_LINKER_FLAGS="-L/home/attila/libiconv-1.18/android-build/lib /home/attila/libiconv-1.18/android-build/lib/libiconv.so" \
-DCMAKE_SHARED_LINKER_FLAGS="-L/home/attila/libiconv-1.18/android-build/lib /home/attila/libiconv-1.18/android-build/lib/libiconv.so"
-DGDCM_ICONV_INCLUDE_DIR=/home/attila/libiconv-1.18/android-build/include
There was another problem:
On Android, far is sometimes defined as a macro (especially in <sys/types.h> or
/home/attila/ITK/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.c:5022:20: error: expected identifier or '('
5022 | float *far = (float *)dataptr ; size_t jj,nj ;
| ^
/home/attila/ITK/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.c:5025:34: error: expected expression
5025 | if( !IS_GOOD_FLOAT(far[jj]) ){
| ^
/home/attila/ITK/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.c:5026:18: error: expected expression
5026 | far[jj] = 0 ;
| ^
/home/attila/ITK/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.c:5034:21: error: expected identifier or '('
5034 | double *far = (double *)dataptr ; size_t jj,nj ;
| ^
/home/attila/ITK/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.c:5037:34: error: expected expression
5037 | if( !IS_GOOD_FLOAT(far[jj]) ){
| ^
/home/attila/ITK/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.c:5038:18: error: expected expression
5038 | far[jj] = 0 ;
| ^
This could be overcome by forcing CMake to override the far macro by adding this flag to the configure line:
-DCMAKE_C_FLAGS="-Dfar=far_nifti" \
So the final configure line was this:
cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_HOME/ndk/28.0.12916984/build/cmake/android.toolchain.cmake \
-S /home/attila/ITK \
-B /home/attila/ITK/itk-build \
-DANDROID_ABI=arm64-v8a \
-DANDROID_PLATFORM=android-21 \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=ON \
-DITK_BUILD_DEFAULT_MODULES=ON \
-DITK_WRAP_PYTHON=OFF \
-DCMAKE_CROSSCOMPILING_EMULATOR="" \
-DHAVE_CLOCK_GETTIME_RUN=1 \
-DITK_USE_SYSTEM_ZLIB=ON \
-D_libcxx_run_result=0 \
-D_libcxx_run_result__TRYRUN_OUTPUT="" \
-DGDCM_USE_SYSTEM_ICONV=ON \
-DCMAKE_C_FLAGS:STRING="-I/home/attila/libiconv-1.18/android-build/include -Dfar=far_nifti" \
-DCMAKE_CXX_FLAGS:STRING="-Dfar=far_nifti" \
-DCMAKE_EXE_LINKER_FLAGS="-L/home/attila/libiconv-1.18/android-build/lib /home/attila/libiconv-1.18/android-build/lib/libiconv.so" \
-DCMAKE_SHARED_LINKER_FLAGS="-L/home/attila/libiconv-1.18/android-build/lib /home/attila/libiconv-1.18/android-build/lib/libiconv.so"
-DGDCM_ICONV_INCLUDE_DIR=/home/attila/libiconv-1.18/android-build/include
A few shortcomings:
This project relies on the [“Builds of Slicer for ARM-based systems Mac and Linux”] project (https://projectweek.na-mic.org/PW42_2025_GranCanaria/Projects/BuildsOfSlicerForArmBasedSystemsMacAndLinux/)