Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 326
saplingPro Avatar asked May 31 '11 08:05

saplingPro


1 Answers

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.

like image 117
Maverik Avatar answered Oct 15 '22 23:10

Maverik