Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calling C from java

 
chandana nannapaneni
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Firstly, I am sorry if this topic is in a wrong forum(I didnot find an appropiate forum to post this).

My aim is to call a C function from java. I got "java.lang.UnsatisfiedLinkError: Can't load library" error. Let me explain what I have done.

I wrote a java program as,

public class ReadFile {
native void loadFile(String name);
static {
System.load("C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\ nativelib.obj");
}
public static void main(String args[]) {
ReadFile mappedFile=new ReadFile();
mappedFile.loadFile("ReadFile.java");
}
}

Then, I generated ReadFile.class and ReadFile.h files
After that I wrote a C program as,

#include <jni.h>
JNIEXPORT void JNICALL Java_ReadFile_loadFile
(JNIEnv * env, jobject jobj, jstring name) {
printf("yahoo, i am into the C program");
return 0;
}

Now at the VB command prompt, I generate the library files
When I run the ReadFile program, I get
Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: C
:\Program Files\Microsoft Visual Studio 9.0\VC\ nativelib.obj
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at ReadFile.<clinit>(ReadFile.java:8)
Could not find the main class: ReadFile. Program will exit.

Can anyone help me with this.

 
chandana nannapaneni
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured out my mistake.
I should load .dll file instead of the .obj file.
I am sorry for this topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic