herumi / mcl

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

compiling shared library with ndk #47

Closed openluopworld closed 5 years ago

openluopworld commented 5 years ago

Hi, how could I compile a shared library with the full code using ndk? Thanks.

** Why I ask I need to use MCL with my project. So the following code is used first, it succeeds to generate libmcl.so.

include $(CLEAR_VARS)
LOCAL_SHARED_LIBRARIES := gmp gmpxx crypto
LOCAL_MODULE := mcl
LOCAL_ARM_NEON := true
LOCAL_SRC_FILES := ./src/fp.cpp \
    ./src/bn_c384.cpp
LOCAL_CFLAGS += -I$(LOCAL_PATH)/include/
LOCAL_CFLAGS += -Wall
LOCAL_CPPFLAGS += -fexceptions
include $(BUILD_SHARED_LIBRARY)

But there are some error when using libmcl.so to compile my project.

/home/luopeng/my_sec_data/jni/include/mcl/fp.hpp:530: error: undefined reference to 'mcl::fp::detectIoMode(int, std::__ndk1::ios_base const&)'
/home/luopeng/my_sec_data/jni/include/mcl/fp_tower.hpp:474: error: undefined reference to 'mcl::fp::detectIoMode(int, std::__ndk1::ios_base const&)'

Then I notice that detectIoMode is under a macro. So I add the following compile option.

LOCAL_CPPFLAGS += -DCYBOZU_DONT_USE_STRING

But it fails to generate the libmcl.so.

/home/luopeng/mcl/mcl/jni/include/mcl/gmp_util.hpp:714:45: error: too few arguments to function call, expected at least 3, have 2
printf("\"%s\",\n", mcl::gmp::getStr(p, 16).c_str());
~~~~~~~~~~~~~~~~      ^                    

So, do you have any advice? thanks.

openluopworld commented 5 years ago

Maybe the macro here is wrong, https://github.com/herumi/mcl/blob/master/include/mcl/gmp_util.hpp#L711, thanks.