Giter VIP home page Giter VIP logo

Comments (9)

Rupan avatar Rupan commented on July 17, 2024

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.

ngingric avatar ngingric commented on July 17, 2024

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.

Rupan avatar Rupan commented on July 17, 2024

Awesome. Resolving issue.

from gmp.

cesards avatar cesards commented on July 17, 2024

@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.

ngingric avatar ngingric commented on July 17, 2024

@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.

cesards avatar cesards commented on July 17, 2024

@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.

cesards avatar cesards commented on July 17, 2024

here is the whole code... @ngingric
https://github.com/m3n0R/NDKFactorial
I've tried everything :-( I'm a little bit desperate!

from gmp.

Rupan avatar Rupan commented on July 17, 2024

I'll look at this later tonight if I have time.

from gmp.

cesards avatar cesards commented on July 17, 2024

Thank you mate. I'd be so grateful!

from gmp.

Related Issues (8)

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.