c++ - issue creating java native interface -
i tried implement jni.
first create java class containing 1 native method, , compile using "javac helloworld.java" , create header file using "javah helloworld" ... here code
class helloworld { private native void print(); public static void main(string[] args) { new helloworld().print(); } static { system.loadlibrary("helloworld"); } }
helloworld.h file shown below .....
/* not edit file - machine generated */ #include /* header class helloworld */ #ifndef _included_helloworld #define _included_helloworld #ifdef __cplusplus extern "c" { #endif /* * class: helloworld * method: print * signature: ()v */ jniexport void jnicall java_helloworld_print (jnienv *, jobject); #ifdef __cplusplus } #endif #endif
after created helloworld.c file ... here code
#include #include #include "helloworld.h" jniexport void jnicall java_helloworld_print(jnienv *env, jobject obj) { printf("hello world!\n"); return; }
and compile helloworld.c file using below mention command in visual studio 2008
cl -ic:\java\jdk\include -ic:\java\jdk\include\win32 -md -ld helloworld.c -fehelloworld.dll
it compiles pretty , dll , other files created in same bin folder "helloworld.class" file . while running java file using "java helloworld" command msvcr90.dll file missing error occurs.... tried reinstall jdk still same problem
what should ...
this error related build settings in visual studio. can select static link of crt library (use /mt option instead /md) or copy msvcr90.dll directory helloworld.dll or other directory in %path%.
Comments
Post a Comment