herumi / mcl

a portable and fast pairing-based cryptography library
BSD 3-Clause "New" or "Revised" License
450 stars 151 forks source link

Cmake cross compile question #183

Open anakinxc opened 11 months ago

anakinxc commented 11 months ago

Hi,

I'm trying to cross compile mcl for Android from a Linux x64 machine.

Here's the command I run:

cmake -GNinja -DCMAKE_SYSTEM_NAME=Android -DCMAKE_ANDROID_NDK=$ANDROID_NDK_HOME -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a -DMCL_BUILD_TESTING=OFF -DMCL_TEST_WITH_GMP=OFF ..
ninja

Error message is:

[1/12] Generating bint64.o
warning: overriding the module target triple with x86_64-unknown-linux-gnu [-Woverride-module]
1 warning generated.
[2/12] Generating base64.o
warning: overriding the module target triple with x86_64-unknown-linux-gnu [-Woverride-module]
1 warning generated.
[6/12] Linking CXX shared library lib/libmcl.so
FAILED: lib/libmcl.so
: && /tools/android/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 -fPIC -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fexceptions -frtti -stdlib=libc++ -O2 -g -DNDEBUG  -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Wl,--gc-sections -Qunused-arguments -Wl,--no-undefined -shared -Wl,-soname,libmcl.so -o lib/libmcl.so CMakeFiles/mcl.dir/src/fp.cpp.o  bint64.o  base64.o   -static-libstdc++ -latomic -lm && :
ld: error: bint64.o is incompatible with aarch64linux
ld: error: base64.o is incompatible with aarch64linux
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
[9/12] Building CXX object CMakeFiles/mclbn384_256.dir/src/bn_c384_256.cpp.o
ninja: build stopped: subcommand failed.

Looks like in CMakeLists.txt:175 when compile LLVM bitcode target triple is missing.

I noticed you have done something for makefile here. Maybe same fix should apply to CMake build?

Best

herumi commented 11 months ago

Is this correct? I'm still determining. https://github.com/herumi/mcl/commit/fa658457becdecdfec27965688c73dd060f6ecba