java - How to compile dynamic library with static files (.a) for a JNI application on linux? -


i'm using ubuntu 14.04

i'm new in jni i'm not familiar in jni , english. i'm using ubuntu 14.04

what did

java

class hello {         public native void sayhello();          static { system.loadlibrary("myapp"); }          public static void main(string[] args){                 new hello().sayhello();         } } 

compile java code , make header file command

javac hello.java  javah hello 

c code

#include "myapp.h" jniexport void jnicall java_hellojni_sayhello (jnienv *env, jobject job ){     printf("saying hello\n"); } 

compile c code command (and have 5 static compiled library *.a).

gcc -shared -fpic -o libmyapp.so -i"path/to/include/jni" -i"path/to/include/myapp" path/to/lib/libmyapp1.a path/to/lib/libmyapp2.a path/to/lib/libmyapp3.a path/to/lib/libmyapp4.a path/to/lib/libmyapp5.a -lm -lpthread -lc -lz hello.c   

that generates file libmyapp.so

after compilation, check function naming nm:

$ nm libmyapp.so | grep  00000000000031a0 t _java_hello_sayhello 

i got error when try run java -djava.library.path=src/ hello have error:

java: symbol lookup error: /path/to/myapplication.so : undefined symbol: myfunc_init 

so in mind, obviously, there wrong during compilation of c shared library.

why symbol lookup error every time want call myfunc_init, reason? please provide solution , correct way compile shared library. , possible load static library below java 7.if not possible how can build dynamic library static one.

i hope able provide information.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -