• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

calling C from java

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic