• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling an Existing C function from JNI wrapper  RSS feed

 
Sanjeeva Timmareddy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

Getting an error when I call an existing C functionlity withing my JNI wrapper.

Error Message:
******************************************************************************************
/usr/lib/dld.sl: Unresolved symbol: OutputTemplate (data) from ./libHelloWorldLib.sl
/usr/lib/dld.sl: Unresolved module for symbol: ParseExperian (code) from ./libHelloWorldLib.sl
/usr/lib/dld.slAbort(coredump)

******************************************************************************************

I have crated a jni wrapper and from which I am calling a function in an existing C programe.

the method signature of an exusting c functionality is like this:
"int PE(char *pReport, char *pOutput)".

what are corresponding datatypes do I need to pass in order this to work.

tnx
Tiger
 
Henry Wong
author
Sheriff
Posts: 22864
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java will load the wrapper library (with the JNI code you wrote) to make the call to C/C++. From there, you are in the realm of C/C++.

In this case, you are making a call (from C/C++) to code that is not in the wrapper library. You need to add the dependent libraries to your library path -- which is operating system dependent.

For Unix (which I am guessing you are using), this is done with the LD_LIBRARY_PATH environment variable.

Henry
 
Sanjeeva Timmareddy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
All the libraries are on the same path I mean current path where I am executing the existing c as well as my expermentations.

Existing Functionality:

I make a call to "int PE(char *pReport, char *pOutput)" in "parseexp.c" from "testexp.c".

*************************** parseexp.c ******************************
"int PE(char *pReport, char *pOutput)
{
.................
................
} "
***************************************************************************


******************************* testexp.c *********************************
char outrec[20000];
int ret;
if (ret=PE("",outrec)) {
printf("Error: %d\n",ret);
} else {
printf("%s\n",outrec);
}
***************************************************************************

the outrec variable is populated with some xml data.

My implementation:

I have written a wrapper to call the same c function and here is the code

************************** HelloWorld.c *****************************
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
printf("Hello world! namskara \n");

jchar outrec[20000];
jint ret;
if (ret=PE(" some text here ",outrec))
{
printf("Error: %d\n",ret);
} else {
printf("%s\n",outrec);
}
***********************************************************************

when I run the i get the earlier error message.

and all my files java's, c's , object libs, shared libs are all reside in the same directory.

I use following commands to

1) javac HelloWorld.java
2) javah -jni HelloWorld
3) cc -Ae +u4 +z -c -D_HPUX \ -I/opt/java1.4/include
-I/opt/java1.4/include/hp-ux \ HelloWorld.c
4) ld -b -o libHelloWorldLib.sl HelloWorld.o
5) export SHLIB_PATH=.;
6) java HelloWorld


I have few concern here
1) Are the data types I am passing to PE() are correct.if not what to pass???
2) Do I need to set any evnt variables?

cheersz
redsan74
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!