Comments (9)
That looks almost right. Android.mk looks good, but you've got APP_MODULES wrong in Application.mk: see the NDK documentation. You should either not define APP_MODULES at all, or list all required modules including your 'foo' module as documented here:
http://source-android.frandroid.com/ndk/docs/APPLICATION-MK.html
from gmp.
I got it to work, thanks so much Rupan for this git repository!
I guess I had an issue with LOCAL_PATH, wanted to post my solution in case someone else runs into the same issue:
Android.mk
JNI_DIR := $(call my-dir)
##### Build gmp as static library #####
include $(JNI_DIR)/gmp/Android.mk
##### restore JNI directory as local path
LOCAL_PATH := $(JNI_DIR)
include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_SRC_FILES := foo.cpp
LOCAL_SHARED_LIBRARIES := gmp
include $(BUILD_SHARED_LIBRARY)
from gmp.
Awesome. Resolving issue.
from gmp.
@ngingric Same problem here... I'm newbie with NDK and I'm getting mad trying to calculate Factorial with this library. Could you give me a sample project or something or tell me what I'm doing wrong? Here is my code:
Application.mk
# The ARMv7 is significanly faster due to the use of the hardware FPU APP_ABI := armeabi armeabi-v7a APP_MODULES := gmp
Android.mk
JNI_DIR := $(call my-dir) ##### Build gmp as static library ##### include $(JNI_DIR)/gmp/Android.mk ##### restore JNI directory as local path LOCAL_PATH := $(JNI_DIR) include $(CLEAR_VARS) LOCAL_MODULE := fac LOCAL_SRC_FILES := fac.c LOCAL_SHARED_LIBRARIES := gmp include $(BUILD_SHARED_LIBRARY)
fac.c
#include jni.h #include math.h #include stdio.h #include string.h #include gmp.h #include assert.h void factorial(int n) { int i; mpz_t p; mpz_init_set_ui(p,1); for (i = 1;...){ mpz_mul_ui(p,p,i); /* p = p * i */ } mpz_out_str(stdout,10,p); mpz_clear(p); } JNIEXPORT void JNICALL Java_com_menor_android_factorial_HomeActivity_factorial (JNIEnv *env, jclass clazz) { int number = 100; factorial(number); }
HomeActivity.java (part of it)
... // load the library - name matches jni/Android.mk static { System.loadLibrary("gmp"); System.loadLibrary("fac"); } // declare the native code function - must match ndkfoo.c public native void fac(); ...
I'm getting this error:
06-06 20:24:23.100: E/AndroidRuntime(7665): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load factorial from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.menor.android.factorial-2.apk,libraryPath=/data/app-lib/com.menor.android.factorial-2]: findLibrary returned null
Lot of thanks!!
PS: @Rupan I think I did the same as @Rupan but it's not working for me :(
from gmp.
@M3N0R Hey,
Just glancing at your code the error message appears to be referring to this line:
System.loadLibrary("factorial");
I see no module in the code you provided with the name factorial.
I also do not see a factorial.h file in the GMP git repository here.
The fact() fucntion appears to be part of the GMP library.
I would remove the line:
System.loadLibrary("factorial");
Hope that helps!
from gmp.
@ngingric sorry! I made a mistake. I've updated the post. I load both libraries because @Rupan says to do it in "usage" section:
...
System.loadLibrary("gmp");
System.loadLibrary("myBNmodule");
...
from gmp.
here is the whole code... @ngingric
https://github.com/m3n0R/NDKFactorial
I've tried everything :-( I'm a little bit desperate!
from gmp.
I'll look at this later tonight if I have time.
from gmp.
Thank you mate. I'd be so grateful!
from gmp.
Related Issues (8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gmp.