Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AJDT » C/C++ Programs From Java using JNI
C/C++ Programs From Java using JNI [message #596036] Mon, 26 March 2007 10:45 Go to next message
Sabeesh C.S. is currently offline Sabeesh C.S.Friend
Messages: 21
Registered: July 2009
Junior Member
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
Re: C/C++ Programs From Java using JNI [message #698137 is a reply to message #596036] Mon, 18 July 2011 21:17 Go to previous message
Cmlo  is currently offline Cmlo Friend
Messages: 7
Registered: May 2011
Junior Member
Which directory do you place the *.c, *.o, *.h and makefile in from the Eclipse ?
Previous Topic:Pointcut with annotations
Next Topic:operator precedence issue?
Goto Forum:
  


Current Time: Mon Jun 18 17:04:52 GMT 2018

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

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

Back to the top