How to write code to call JNI using microsoft visual c++ [closed]

|▌冷眼眸甩不掉的悲伤 提交于 2020-12-01 10:15:55

问题


Screen Grab

How do I write C code in microsoft visual c++ 2010 Express? I am unable to do it. I was writing some C code but it is compiled with errors.

Please suggest some way to do it?

I wrote this code:

#include "jni.h"
#include "stdio.h"
#include "HelloWorld.h"

JNIEXPORT void JNICALL
Java_HelloWorld_print(JNIEnv *env, jobject obj) {
    printf("This is a JNI tester");
    return;
}

I got the following error:

helloworld.cpp(1): fatal error C1083: Cannot open include file: 'jni.h' No such file or directory


回答1:


I've never done JNI specific code but your error says it cannot find the file "jni.h". You probably need to drop that file inside your solution file or go in project options and in C/C++ options specify the folder where JNI header files are located. I'd recommend the later approach i.e. add the folder in include options of project.

Specific steps are:

  1. go to your project properties

  2. navigate in the tree to "Configuration Properties->C/C++" then look at the first entry "Additional Include Directories"

  3. in there enter the path: "*JDKVersionPath*\include";"*JDKVersionPath*\include\win32"

Where JDKVersionPath is where your JDK install resides like C:\Program Files\Java\jdk1.6.0\ (the path version can especially vary depending on the version you have installed.



来源:https://stackoverflow.com/questions/6185169/how-to-write-code-to-call-jni-using-microsoft-visual-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!