Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved compiling for android with Mac m1 #302

Closed
jesili opened this issue Jul 26, 2024 · 1 comment
Closed

Solved compiling for android with Mac m1 #302

jesili opened this issue Jul 26, 2024 · 1 comment

Comments

@jesili
Copy link

jesili commented Jul 26, 2024

Environment:

Host: Macbook Pro m1 pro
Target: arm64-android
I modify the bash script (/preset/armdroid-pbc-bn254.sh) to adapt to the newer NDK (ndk 27), since the toolchain has been chained, it now works with android.toolchain.cmake, and i don't need to build the standalone toolchain.

#!/bin/sh

NDK=path/to/ndk/
SYSROOT=$NDK/toolchains/llvm/prebuilt/darwin-x86_64/sysroot
API=23
TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/darwin-x86_64
CMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake
TARGET=aarch64-linux-android

cmake -DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE \
      -DANDROID_ABI=arm64-v8a \
      -DANDROID_PLATFORM=android-$API \
      -DCMAKE_SYSROOT=$SYSROOT \
      -DANDROID_TOOLCHAIN=clang \
      -DANDROID_STL=c++_shared \
      -DCMAKE_BUILD_TYPE=Release \
      -DWITH="DV;BN;MD;FP;EP;FPX;EPX;PP;PC;CP" \
      -DCHECK=off \
      -DARITH=easy \
      -DARCH=ARM \
      -DCOLOR=off \
      -DOPSYS=DROID \
      -DFP_PRIME=254 \
      -DFP_QNRES=on \
      -DFP_METHD="INTEG;INTEG;INTEG;MONTY;EXGCD;LOWER;SLIDE" \
      -DFPX_METHD="INTEG;INTEG;LAZYR" \
      -DPP_METHD="LAZYR;OATEP" \
      -DCFLAGS="-O3 -funroll-loops -fomit-frame-pointer" \
      -DLDFLAGS="-L$SYSROOT/usr/lib/$TARGET/$API/ -llog" \
      -DTIMER=HREAL \
      -DWSIZE=32 \
      -DSTLIB=on \
      -DSHLIB=off \
      $1

When i run the script, i met the error:

$/relic/include/relic_types.h:169:23: error: typedef redefinition with different types ('unsigned long' vs 'unsigned int')
  169 | typedef unsigned long uint_t;
      |                       ^
$/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/sys/types.h:131:29: note: previous definition is here
  131 | typedef unsigned int        uint_t;

It conflicts with the definition in android library, so i rename all the uint_t in relic to relic_uint_t. And this works.

Then i run the make command, the following error occurs:

[ 85%] Linking C executable ../bin/test_bn
ld.lld: error: undefined symbol: __android_log_vprint
>>> referenced by relic_util.c
>>>               relic_util.c.o:(util_printf) in archive ../lib/librelic_s.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [test/CMakeFiles/test_bn.dir/build.make:98: bin/test_bn] Error 1
make[1]: *** [CMakeFiles/Makefile2:256: test/CMakeFiles/test_bn.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

So i modify the CMakeLists.txt in /test and /bench as follows:
target_link_libraries(test_${MODULE} ${RELIC_S}) to target_link_libraries(test_${MODULE} ${RELIC_S} log).
target_link_libraries(bench_${MODULE} ${RELIC_S}) to target_link_libraries(bench_${MODULE} ${RELIC_S} log).
And this fixes the bugs. I try to remove option -DLDFLAGS="-L$SYSROOT/usr/lib/$TARGET/$API/ -llog" \ in the bash file, it can still work, since the android toolchain can find the relate library. Additionally, i try to use the -DARITH=arm-asm-254, it does work, and the following error occurs:
/relic/src/low/arm-asm-254/relic_fp_add_low.s:644:6: error: invalid operand for instruction STR r5, [r0, #0]

@dfaranha
Copy link
Contributor

Thanks for reporting! Closing because apparently all problems have been fixed with minor updates. A PR with the changes would be welcome, BTW!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants