• 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 an Existing C function from JNI wrapper

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
This is my favorite 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