H
Hunter McMillen
Guest
I am trying to use the Java Native Interface(JNI) to compile and run a simple program. I am following the steps found here: Oracle Technology Network for Java Developers | Oracle Technology Network | Oracle
I have gone through the first several steps successfully.
1) I created a Java program with appropriate native methods
2) I called javah -jni on my class file to create the C style header file
3) I wrote the implementation specified by the header in C++
I initially tried running this command:
cl
-I"C:\Program Files\Java\jdk1.7.0\include"
-I"C:\Program Files\Java\jdk1.7.0\include\win32" -MD -LD HelloJNI.cpp
-FeHelloJNI.dll
but when I ran this I got an error:
C:\Program Files\Java\jdk1.7.0\include\jni.h(39) : fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory
So the command I am trying to run now is:
cl
-I"c:/Program Files (x86)/Microsoft Visual Studio 9.0/Common7/IDE"
-I"c:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/include"
-I"c:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/lib"
-I"c:/Program Files/Java/jdk1.7.0/include" -I"c:/Program Files/Java/jdk1.7.0/include/win32"
-LD HelloJNI.cpp -FeHelloJNI.dll
And When I run this I get:
LINK : fatal error LNK1104: cannot open file 'libcpmt.lib'
Which doesn't make any sense to me beucause 'libcpmt.lib' is on my PATH variable and should be including in the cl command because I point -I to the directory it is in.
Has anyone encountered this issue?
Any help would be great.
Thanks
Continue reading...
I have gone through the first several steps successfully.
1) I created a Java program with appropriate native methods
- public class HelloJNI
- {
- private native void print();
- public static void main(String[] args)
- {
- new HelloJNI().print();
- }
- static
- {
- System.loadLibrary("HelloJNI");
- }
- }
2) I called javah -jni on my class file to create the C style header file
3) I wrote the implementation specified by the header in C++
- #include <jni.h>
- #include <iostream>
- #include "HelloJNI.h"
- using namespace std;
- JNIEXPORT void JNICALL
- Java_HelloJNI_print(JNIEnv *env, jobject obj)
- {
- cout << "Hello JNI!" << endl;
- return;
- }
I initially tried running this command:
cl
-I"C:\Program Files\Java\jdk1.7.0\include"
-I"C:\Program Files\Java\jdk1.7.0\include\win32" -MD -LD HelloJNI.cpp
-FeHelloJNI.dll
but when I ran this I got an error:
C:\Program Files\Java\jdk1.7.0\include\jni.h(39) : fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory
So the command I am trying to run now is:
cl
-I"c:/Program Files (x86)/Microsoft Visual Studio 9.0/Common7/IDE"
-I"c:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/include"
-I"c:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/lib"
-I"c:/Program Files/Java/jdk1.7.0/include" -I"c:/Program Files/Java/jdk1.7.0/include/win32"
-LD HelloJNI.cpp -FeHelloJNI.dll
And When I run this I get:
LINK : fatal error LNK1104: cannot open file 'libcpmt.lib'
Which doesn't make any sense to me beucause 'libcpmt.lib' is on my PATH variable and should be including in the cl command because I point -I to the directory it is in.
Has anyone encountered this issue?
Any help would be great.
Thanks
Continue reading...