Sunday 15 April 2012

c - Getting /usr/bin/ld: cannot find -ljvm collect2: ld returned 1 exit status make: *** [hello_world] Error 1 while trying to call java class method -



c - Getting /usr/bin/ld: cannot find -ljvm collect2: ld returned 1 exit status make: *** [hello_world] Error 1 while trying to call java class method -

i m trying phone call java class methods c jni.i have made simple hello_world.java , hello_world.c , makefile while executing create command getting next errors . please help me out

make gcc hello_world.c -o hello_world \ -l /usr/java/latest/jre/lib/i386/server/ \ -ljvm \ -i /usr/java/latest/include/ \ -i /usr/java/latest/include/linux/ \ hello_world.c /usr/bin/ld: skipping incompatible /usr/java/latest/jre/lib/i386/server//libjvm.so when searching -ljvm /usr/bin/ld: cannot find -ljvm collect2: ld returned 1 exit status make: *** [hello_world] error 1

public class hello_world{ public static void main(string[] args){ system.out.println("hello, world"); } public static int square(int input){ int output = input * input; homecoming output; } public static int power(int input, int exponent){ int output,i; output=1; for(i=0;i<exponent;i++){ output *= input; } homecoming output; } } #include <stdio.h> #include <jni.h> jnienv* create_vm(javavm **jvm) { jnienv* env; javavminitargs args; javavmoption options; args.version = jni_version_1_6; args.noptions = 1; options.optionstring = "-djava.class.path=./"; args.options = &options; args.ignoreunrecognized = 0; int rv; rv = jni_createjavavm(jvm, (void**)&env, &args); if (rv < 0 || !env) printf("unable launch jvm %d\n",rv); else printf("launched jvm! :)\n"); homecoming env; } void invoke_class(jnienv* env) { jclass hello_world_class; jmethodid main_method; jmethodid square_method; jmethodid power_method; jint number=20; jint exponent=3; hello_world_class = (*env)->findclass(env, "helloworld"); main_method = (*env)->getstaticmethodid(env, hello_world_class, "main", "([ljava/lang/string;)v"); square_method = (*env)->getstaticmethodid(env, hello_world_class, "square", "(i)i"); power_method = (*env)->getstaticmethodid(env, hello_world_class, "power", "(ii)i"); (*env)->callstaticvoidmethod(env, hello_world_class, main_method, null); printf("%d squared %d\n", number, (*env)->callstaticintmethod(env, hello_world_class, square_method, number)); printf("%d raised %d powerfulness %d\n", number, exponent, (*env)->callstaticintmethod(env, hello_world_class, power_method, number, exponent)); } int main(int argc, char **argv) { javavm *jvm; jnienv *env; env = create_vm(&jvm); if(env == null) homecoming 1; invoke_class(env); homecoming 0; } all:run hello_world.class:hello_world.java /usr/java/latest/bin/javac hello_world.java hello_world: hello_world.c gcc -o hello_world \ -l /usr/java/latest/jre/lib/i386/server/ \ -ljvm \ -i /usr/java/latest/include/ \ -i /usr/java/latest/include/linux/ \ hello_world.c run: hello_world.class hello_world export ld_library_path="/usr/java/latest/jre/lib/i386/server/" ./hello_world clean: rm -f hello_world.class hello_world

-ljvm transform gcc libjvm.so , seek find -l paths. seek folder if find .so

java c gcc makefile

No comments:

Post a Comment