Git Product home page Git Product logo

gmp's Introduction

GMP for Android

This repository contains a prebuilt copy of GMP 6.2.0 compiled with the Android NDK r21 against API level 24.

Compiling against API levels greater than or equal to 21 will produce backwards incompatible binaries which reference localeconv() unless special care is taken. It is advised to check config.h at each build and confirm that localeconv is not enabled.

The C++ bindings are included; they depend on libgmp.so, so you will need to ship both in your APK for each platform you support.

Installation and usage in an Android project

  1. Check out a copy of this repository into your jni folder, using something like this:

    $ git submodule add git://github.com/Rupan/gmp.git jni/gmp

  2. Add "gmp" to APP_MODULES in jni/Application.mk

  3. Add "gmp" to LOCAL_SHARED_LIBRARIES in your module's Android.mk as required.

  4. Use GMP as normal by including gmp.h in your source files where required.

  5. Build the rest of your native code as you would normally:

    $ ndk-build

A basic top-level Android.mk might look like this:

JNI_PATH := $(call my-dir)

# Uncomment the following line to include GMP's C++ bindings in your APK
#GMP_WITH_CPLUSPLUS := yes
include $(JNI_PATH)/gmp/Android.mk

LOCAL_PATH := $(JNI_PATH)
include $(CLEAR_VARS)

LOCAL_MODULE := myBNmodule
LOCAL_SRC_FILES := myBNmodule.c

LOCAL_LDLIBS += -llog
LOCAL_SHARED_LIBRARIES := gmp
include $(BUILD_SHARED_LIBRARY)

Inclusion via Android Studio is covered here: https://developer.android.com/studio/projects/add-native-code.html#link-gradle

Usage at runtime

The GMP library must be loaded prior to other dependent modules. This is an apparent shortcoming of Android. To handle this condition, do something like the following in your Java source code:

// ...
System.loadLibrary("gmp");
System.loadLibrary("myBNmodule");
// ...

The scripts used to compile and package the prebuilt libraries is named "compile-gmp-{arm,mips,x86}.sh". The build procedure is documented therein.

An example of how to use this library is here: https://github.com/Rupan/GMPtest

Notes

The testsuite cannot be easily run on a target device. The autoconf system which runs the test binaries cannot simply be copied from the build host to the target device and run. The next best thing is to copy the compiled binaries onto a target and run them by hand - but apparently this does not fully run the test suite. Still, it is better than nothing since it exercises various GMP code paths and proves that the library will not crash when used in an APK. prep-tests.sh and run-tests.sh are now provided; using them is left as an exercise to the reader.

An armeabi-v7a-neon build is now provided. To use it, move the shared object from the armeabi-v7a-neon directory into the armeabi-v7a directory as e.g. "libgmp-neon.so". You'll have to hack up Android.mk so it copies the new shared object together with the existing one. Then the correct shared object must be selected at runtime by the application using the cpufeatures static library. See the NDK documentation, or just stick with the armeabi-v7a build.

When using the "modern" 64-bit builds (i.e., arm64-v8a / x86_64 / mips64) your app must target, at a minimum, Android API level 21.

Build Reproducibility

In order to reproduce the binaries hosted here, you'll need the following environment:

  • Host operating system: Ubuntu 19.10, x86_64
  • NDK toolchain: revision 21 (android-ndk-r21)
  • GMP 6.2.0 source code decompressed in /tmp/gmp-6.2.0

gmp's People

Contributors

cgutman avatar rupan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gmp's Issues

x86 & MIPS binaries

Hi,

Thanks for the latest repo update it works a treat.

Would you please if possible include x86 and MIPS compiled binaries to the set.

I have tried to build gmp-5.0.5 myself using Cygwin under Win 7 Ultimate x64 but have got errors I have not been able to resolve.
I am busy building an Ubuntu v12.04 machine (using VM Virtual box) so that I have the same build environment you describe but have not completed it yet.

In the meantime I would apreciate any pointers with where my problem may be in building the library,

I changed the first export command (in compile-gmp.sh) to export NDK="/cygdrive/f/Android/android-ndk-r8b" (which is the correct path for the NDK) and I get the following when running the script,

Deon Marais@Deon-Desktop-Ne /cygdrive/f/Android/gmp-5.0.5
$ ./compile-gmp.sh
checking build system type... i686-pc-linux-gnu
checking host system type... arm-unknown-linux-androideabi
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-linux-androideabi-strip... arm-linux-androideabi-strip
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking ABI=standard
checking compiler arm-linux-androideabi-gcc -O2 -pedantic -fomit-frame-pointer -march=armv7-a -mfloat-abi=softfp -mfpu=neon -ftree-vectorize -ftree-vectorizer-verbose=2 ... yes
checking whether ARM gcc unsigned division works... yes
checking for arm-linux-androideabi-gcc... arm-linux-androideabi-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether arm-linux-androideabi-gcc accepts -g... yes
checking for arm-linux-androideabi-gcc option to accept ISO C89... none needed
checking for arm-linux-androideabi-gcc option to accept ISO C99... -std=gnu99
checking for arm-linux-androideabi-gcc -std=gnu99 option to accept ISO Standard C... (cached) -std=gnu99
checking how to run the C preprocessor... arm-linux-androideabi-gcc -std=gnu99 -E
checking build system compiler arm-linux-androideabi-gcc -std=gnu99... no
checking build system compiler arm-linux-androideabi-gcc -std=gnu99 -O2 -pedantic -fomit-frame-pointer -march=armv7-a -mfloat-abi=softfp -mfpu=neon -ftree-vectorize -ftree-vectorizer-verbose=2 ... no
checking build system compiler cc... no
checking build system compiler gcc... no
checking build system compiler c89... no
checking build system compiler c99... no
configure: error: Cannot find a build system compiler
make: *** No targets specified and no makefile found. Stop.
make: Nothing to be done for install'. ./compile-gmp.sh: line 45: cd: armeabi-v7a-neon: No such file or directory make: *** No rule to make targetdistclean'. Stop.
checking build system type... i686-pc-linux-gnu
checking host system type... arm-unknown-linux-androideabi
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-linux-androideabi-strip... arm-linux-androideabi-strip
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking ABI=standard
checking compiler arm-linux-androideabi-gcc -O2 -pedantic -fomit-frame-pointer -march=armv7-a -mfloat-abi=softfp ... yes
checking whether ARM gcc unsigned division works... yes
checking for arm-linux-androideabi-gcc... arm-linux-androideabi-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether arm-linux-androideabi-gcc accepts -g... yes
checking for arm-linux-androideabi-gcc option to accept ISO C89... none needed
checking for arm-linux-androideabi-gcc option to accept ISO C99... -std=gnu99
checking for arm-linux-androideabi-gcc -std=gnu99 option to accept ISO Standard C... (cached) -std=gnu99
checking how to run the C preprocessor... arm-linux-androideabi-gcc -std=gnu99 -E
checking build system compiler arm-linux-androideabi-gcc -std=gnu99... no
checking build system compiler arm-linux-androideabi-gcc -std=gnu99 -O2 -pedantic -fomit-frame-pointer -march=armv7-a -mfloat-abi=softfp ... no
checking build system compiler cc... no
checking build system compiler gcc... no
checking build system compiler c89... no
checking build system compiler c99... no
configure: error: Cannot find a build system compiler
make: *** No targets specified and no makefile found. Stop.
make: Nothing to be done for install'. ./compile-gmp.sh: line 53: cd: armeabi-v7a: No such file or directory make: *** No rule to make targetdistclean'. Stop.
checking build system type... i686-pc-linux-gnu
checking host system type... arm-unknown-linux-androideabi
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-linux-androideabi-strip... arm-linux-androideabi-strip
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking ABI=standard
checking compiler arm-linux-androideabi-gcc -O2 -pedantic -fomit-frame-pointer ... yes
checking whether ARM gcc unsigned division works... yes
checking for arm-linux-androideabi-gcc... arm-linux-androideabi-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether arm-linux-androideabi-gcc accepts -g... yes
checking for arm-linux-androideabi-gcc option to accept ISO C89... none needed
checking for arm-linux-androideabi-gcc option to accept ISO C99... -std=gnu99
checking for arm-linux-androideabi-gcc -std=gnu99 option to accept ISO Standard C... (cached) -std=gnu99
checking how to run the C preprocessor... arm-linux-androideabi-gcc -std=gnu99 -E
checking build system compiler arm-linux-androideabi-gcc -std=gnu99... no
checking build system compiler arm-linux-androideabi-gcc -std=gnu99 -O2 -pedantic -fomit-frame-pointer ... no
checking build system compiler cc... no
checking build system compiler gcc... no
checking build system compiler c89... no
checking build system compiler c99... no
configure: error: Cannot find a build system compiler
make: *** No targets specified and no makefile found. Stop.
make: Nothing to be done for install'. ./compile-gmp.sh: line 61: cd: armeabi: No such file or directory make: *** No rule to make targetdistclean'. Stop.

Thanks again.

Shared Library Objects include Text Relocations

Using the latest 6.1.2 version of your pre-built libraries, I noticed when compiling on Android 7 (Nougat) using "compileSdkVersion 22" the system presented the warning "Detected problems with app native libraries (please consult log for detail): libgmp.so: text relocations". If I increased the "compileSdkVersion" to 23 or above, the warning changes to a FATAL ERROR, preventing the app from running.

It seems newer versions of Android are disallowing libraries that include text relocations (TEXTRELs) within them. Doing research shows that a GCC compiler flag, -fPIC, can be used to remove text relocations when compiling. Further research showed that GMP shared libraries should use the -fPIC compiler flag by default. This prompted me to check which shared libraries included the TEXTRELs and of the 3 I was using, only the "armeabi" and "armeabi-v7a" libraries included them. Continuing my research showed -fPIC is unable to remove all text relocations from some architecture builds if the TEXTRELs are hand written in assembly; namely ARM builds.

I am logging this issue to ask if -fPIC was indeed enabled for the "armeabi" and "armeabi-v7a" builds. If so, has anyone fixed this issue in another way?

I am discussing the issue on the GMP Discussion email chain now and will most likely move to submitting it as a "bug". However, I want to make sure -fPIC was indeed used to compile the libraries before I mark it as such.

localeconv reference issue in API 19

Hello Rupan,

Firstly a big thanks for this repo. I have used it for my work and it is working pretty fine with android API 23. But, I am facing "dlopen failed: cannot locate symbol "localeconv" referenced by libgmp.so" error while accessing the same for API 19. Kindly suggest me a fix.

Thanks

configure failed. Please help.

Here's my config.log starting from line 340. Any ideas?

configure:10521: checking C++ compiler aarch64-linux-android-g++  -O2 -g -pedantic -fomit-frame-pointer -Wa,--noexecstack -ffunction-sections -funwind-tables -no-canonical-prefixes -fno-strict-aliasing -fstack-protector-strong -finline-limit=300 -funswitch-loops
Test compile: 
configure:10535: aarch64-linux-android-g++  -O2 -g -pedantic -fomit-frame-pointer -Wa,--noexecstack -ffunction-sections -funwind-tables -no-canonical-prefixes -fno-strict-aliasing -fstack-protector-strong -finline-limit=300 -funswitch-loops conftest.cc >&5
clang80++: warning: optimization flag '-finline-limit=300' is not supported [-Wignored-optimization-argument]
clang80++: warning: optimization flag '-funswitch-loops' is not supported [-Wignored-optimization-argument]
/home/hongwu/devel/2020/Android/my-toolchain/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find crtbegin_dynamic.o: No such file or directory
/home/hongwu/devel/2020/Android/my-toolchain/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lc++
/home/hongwu/devel/2020/Android/my-toolchain/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find crtend_android.o: No such file or directory
clang80++: error: linker command failed with exit code 1 (use -v to see invocation)
configure:10538: $? = 1
failed program was:

int main (void) { return 0; }
configure:10650: result: no
configure:10521: checking C++ compiler aarch64-linux-android-g++  -g -O2
Test compile: 
configure:10535: aarch64-linux-android-g++  -g -O2 conftest.cc >&5
/home/hongwu/devel/2020/Android/my-toolchain/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find crtbegin_dynamic.o: No such file or directory
/home/hongwu/devel/2020/Android/my-toolchain/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lc++
/home/hongwu/devel/2020/Android/my-toolchain/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find crtend_android.o: No such file or directory
clang80++: error: linker command failed with exit code 1 (use -v to see invocation)
configure:10538: $? = 1
failed program was:

int main (void) { return 0; }
configure:10650: result: no
configure:10666: error: C++ compiler not available, see config.log for details

Application.mk and Android.mk

Would you mind providing examples for steps 2 and 3?

  1. Add "gmp" to APP_MODULES in jni/Application.mk
  2. Add "gmp" to LOCAL_SHARED_LIBRARIES in your module's Android.mk as required.

I may have other issues, but I wanted to make sure following steps 2 and 3 were not one of them.

Here is what I have at the moment:

Application.mk
APP_MODULES := gmp

Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := foo
LOCAL_SRC_FILES := foo.cpp

LOCAL_SHARED_LIBRARIES := gmp

include $(BUILD_SHARED_LIBRARY)

Thanks!

Static Lib

Hi

I'm using your precompiled library, but I get seg faults when I use for example:
mpz_divexact(z, deg, fac);

Would using a static library perhaps solve this issue? Or is there something that I'm doing wrong?

Every thing builds and links fine when build with ndk-build.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.