Skip to main content



      Home
Home » Language IDEs » AspectJ » C/C++ Programs From Java using JNI
C/C++ Programs From Java using JNI [message #69898] Mon, 26 March 2007 06:45
Eclipse UserFriend
Hi,
Iam using Eclipse 3.2 in Linux. I try to create a programe in Java using
Eclipse, which one execute a function in C/C++. For that I am try to use
JNI methord in JAVA. When i try this, I get one error message,

"
Exception in thread "main" java.lang.UnsatisfiedLinkError: no TestHello in
java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
at java.lang.Runtime.loadLibrary0(Runtime.java:822)
at java.lang.System.loadLibrary(System.java:993)
at TestHello.<clinit>(TestHello.java:8)

"
Please help me to solve the error.

I create a Java project named TestHello and a class (default) named
TestHello, and the contents of the .java file is
==================================================
class TestHello
{
public native void sayHello();
static
{
try
{
System.loadLibrary("TestHello");
}
catch(Exception e)
{
System.out.println("exc");
}
}
public static void main(String[] args)
{
TestHello h = new TestHello();
h.sayHello ();
}
}
========================================================
and save the file. After that I convert this java project into a C
project through, right click on the project -> new -> others -> C ->
convert to a C/C++ Make Project. Then the Perspetive view into C/C++.

create a file named " TestHello.c " and the contents of the file is, and
save the file.

============================================================ =========
#include <jni.h>
#include "TestHello.h"
#include <stdio.h>

JNIEXPORT void JNICALL Java_TestHello_sayHello
(JNIEnv *env, jobject obj)
{
printf("Hello world!\n");
return;
}

============================================================ =========


Write click on the project and create a file named " Makefile " , contents
of the file is, and save.

=========================================
#The space must be a tab, where the * is found ( replace the * and give
SINGLE TAB tab ( NO SPACE ) )


all : TestHello.so

TestHello.so : TestHello.c TestHello.h
* gcc TestHello.c -o TestHello.so -shared -I /usr/java/jdk1.6.0/include/
-I /usr/java/jdk1.6.0/include/linux

TestHello.h : TestHello.class
* javah -jni TestHello

clean :
* -del TestHello.h
* -del TestHello.class
* -del TestHello.so



==================================================

After that, take the properties, and take the C/C++ Make Project. Uncheck
the Use Default option and give the command like " make -f Makefile " .
Check on the option , " Build on Resource save (Auto Build )" and give
the " Make Build Target " variable as " all ". And set " Apply " and " OK
".

After this you get a header file "TestHello.h" a .so file " TestHello.so "
and create a Binaries.

When i run this programe using : Run ->Run.... -> JavaApplication

then an errer message display like this "

Exception in thread "main" java.lang.UnsatisfiedLinkError: no TestHello in
java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
at java.lang.Runtime.loadLibrary0(Runtime.java:822)
at java.lang.System.loadLibrary(System.java:993)
at TestHello.<clinit>(TestHello.java:8)

"



Please help me for solving this problum.




Sabeesh C.S
Previous Topic:AJDT New Feature: Crosscutting Changes
Next Topic:How rename worked in AJDT1.4.1
Goto Forum:
  


Current Time: Sat May 10 09:37:55 EDT 2025

Powered by FUDForum. Page generated in 0.02568 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top