Build error when compiling java methods in C++ using jni.h -


i'm trying run few methods java class in visual studio c++ environment. got error related createjavavm.

would please me find solution?

i did following steps.

step 1: jdk 1.6 installed under following path: c:\program files\java following 2 sub directories there: jdk1.6.0_45, jre6

step 2: write simple java program.

public class sample2 {    public static int intmethod(int n)    {      return n*n;    }    public static boolean booleanmethod(boolean bool)     {     return !bool;     }  } 

step 3: compile java code:

   javac sample2.java 

step 4: create visual studio c++ program. visual c++ clr console application.

step 5: add additional dependencies. (jvm.lib , jvm.dll) a) choose project -> properties -> linker -> input -> additional dependencies: jvm.lib b) choose project -> properties -> linker -> input -> delay loaded dlls: jvm.dll

step 6: add include directories a) choose project -> properties -> configuration properties -> c/c++ -> general -> additional include directories: c:\program files\java\jdk1.6.0_45\lib; c:\program files\java\jdk1.6.0_45\include\win32; c:\program files\java\jdk1.6.0_45\include

step 7: write c++ code run java methods.

  #include "stdafx.h"   #include "jni.h"   #include <jni_md.h>   using namespace system;    int main(array<system::string ^> ^args)   {      javavm *jvm;   /* denotes java vm */     jnienv *env;  /* pointer native method interface */     jint square;     jboolean not;      javavminitargs vm_args; /* jdk/jre 6 vm initialization arguments */      javavmoption *options = new javavmoption[1];      options[0].optionstring = "-djava.class.path=c:\\javacode";       vm_args.version = jni_version_1_6;    vm_args.options = options;    vm_args.noptions = 1;    vm_args.ignoreunrecognized = false;     int res = jni_createjavavm(&jvm, (void **)&env, &vm_args);     jclass cls = env->findclass("sample2");     jmethodid mid = env->getstaticmethodid(cls, "staticint", "(i)i");     env->callstaticvoidmethod(cls, mid,10);     if(cls !=0)    {         mid = env->getstaticmethodid(cls,"intmethod","(i)i");         if(mid !=0)    {       square = env->callstaticintmethod(cls, mid, 5);            printf("result of intmethod: %d\n", square);    }     mid = env->getstaticmethodid(cls, "booleanmethod", "(z)z");      if(mid !=0)     {       not = env->callstaticbooleanmethod(cls, mid, 1);      printf("result of booleanmethod: %d\n", not);     }  }   jvm->destroyjavavm();   console::read();  return 0; } 

step 8: when build project got following error:

1>------ build started: project: 1, configuration: debug win32 ------  1>link : warning lnk4199: /delayload:jvm.dll ignored; no imports found jvm.dll  1>1.obj : warning lnk4248: unresolved typeref token (0100000f) '_jmethodid'; image may not run  1>1.obj : error lnk2028: unresolved token (0a000016) "extern "c" long __stdcall jni_createjavavm(struct javavm_ * *,void * *,void *)" (?jni_createjavavm@@$$j212ygjpapaujavavm_@@papaxpax@z) referenced in function "int __clrcall main(cli::array<class system::string ^ >^)" (?main@@$$hymhp$01ap$aavstring@system@@@z)  1>1.obj : error lnk2019: unresolved external symbol "extern "c" long __stdcall jni_createjavavm(struct javavm_ * *,void * *,void *)" (?jni_createjavavm@@$$j212ygjpapaujavavm_@@papaxpax@z) referenced in function "int __clrcall main(cli::array<class system::string ^ >^)" (?main@@$$hymhp$01ap$aavstring@system@@@z)  1>c:\users\tveluppillai\desktop\test1\1\debug\1.exe : fatal error lnk1120: 2 unresolved externals  ========== build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

would me solve error please?

jni_createjavavm defined in jni.h, guess linker not finding jni.h. put file , jni_md.h in project directory source code.

note jni.h includes jni_md.h, having #include <jni_md.h> in source code redundant.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -