balaji phaneedra kuamr kumar wrote:i have shared object created using gcc (c compiler) not contain any java related things. now i need to call apis present inside the shared object (i dont have c code which used for shared object) using java.
please give small example for that.
This is not exactly something that can be learned with a small example. Basically, you need to write a C wrapper (which conforms to the Java calling standard) that will be called by Java and in turn, can route the request to your C shared object.
The steps are....
1. With Java, create the methods that you want (declared as native methods).
2. Compile the class.
3. Use javah to generate the include file for the C wrapper.
4. With C, create the methods that will take the request from Java and call your share lib. (using the include file)
5. Compile and generate the wrapper shared lib.
6. Modify the Java class to load the wrapper shared lib.
The Sun tutorial is a good place to start (or you can just google for JNI) ....
some coder done this like steps
gcc -c -fPIC calc_mean.c -o calc_mean.o
gcc -shared -Wl,-soname,libmean.so.1 -o libmean.so calc_mean.o
provided only libmean.so not code and i know it contain api as float mean_value(int a,int b);
so have written code like
JNIEXPORT void JNICALL Java_JNIDemo_display(JNIEnv *env, jobject obj)
printf("enter two values\n");
printf("result is %f",result);
public class JNIDemo
public native void display();
public static void main(String args)
JNIDemo jdo=new JNIDemo();
System.out.println("Alert Alert Alert:"+e.getMessage());
now i have done
1)cc -o libnativecode.so -shared -I/JDK/include -I/JDK/include/linux NativeCode.c
then it giving error "java.lang.UnsatisfiedLinkError"
please help me i just want to use that .so file apis in java
i was getting result for .so files which is compiled using java library's but my case is different
iam very new to java (frankly very beginner )
please help me out
it is very urgent, tell me is it possible to use c library (which is compiled with out java libraries) in java.