• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Link Error Which is Never Satisfied

 
kundan vyas
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
Even I am facing a similar problem.I am trying to call a function from kernel32.dll .
My Code
public class HelloWorld {
public native boolean Beep(long freq,long duration);

static {
try{
System.out.println(System.getProperty("java.library.path"));
System.loadLibrary("kernel32");
}
finally
{
System.out.println("arg debug: after loadLibrary");
}

}
public static void main(String[] args) {
HelloWorld obj=new HelloWorld();
boolean flag=obj.Beep(500L,500L);
}
}
I am executing the following steps
1)javac HelloWorld.java
2)javah -jni HelloWorld
3)java HelloWorld
I am getting the following error
java.lang.UnsatisfiedLinkError: Beep at
at HelloWorld.Beep(Native Method)
at HelloWorld.main(HelloWorld.java:20)
I ve also tried the System.load("c:/windows/system/kernel32.dll") method. The library seems to be getting loaded either ways. I think HelloWorld.h header file has some problem.
Do I need to put my HelloWorld.h file in the include folder of JDK. Kindly check this problem.
Kundan
(kundanvyas@yahoo.com)
 
Servin Park
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know, you have to build HelloWorld.dll from HelloWorld.h created by executing javah -jni HelloWorld. You can't just use kernel32.dll. After building HelloWorld.dll, do either System.loadLibrary("HelloWorld") or System.load("C:/path/to/your/HelloWorld.dll");. Refer to Sun's JNI overview. It gives ample explanation on how to program JNI.
[ June 27, 2002: Message edited by: Servin Park ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic