• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Calling an Existing C function from JNI wrapper

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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


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.

Posts: 23879
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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.

Sanjeeva Timmareddy
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 {

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 *****************************
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 {

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?

Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic