Operating System - HP-UX
1829772 Members
7548 Online
109992 Solutions
New Discussion

Unresolved Symbol when calling C code via JNI

 
David Calkins_2
Occasional Contributor

Unresolved Symbol when calling C code via JNI

I'm using Java 1.1.8.04 on HP-UX 10.20.

I have a static library (libStuff.a) with some APIs I need to call from Java. So, I've written a shared library, which links with this static library and makes the calls (libMyStuff.sl). I've written a C executable just to test it out. The executable called the shared library and everything works.

I then created the Java class, with the native methods, and used javah to generate the function prototypes. I tested this with empty implementations and it works (I wanted to make sure I could actually talk to the shared library from Java).

Then, I put the calls to the static library inside the shared library. As soon as I do this, I get the following error when I try to run the Java class:

/usr/lib/dld.sl: Unresolved symbol: SomeAPICall (code) from /somedir/libMyStuff.sl
SIGABRT 6* abort (generated by abort(3) routine)
Sig = 6; code = -1.
stackbase=7B03CE64, stackpointer=7B03E730
IOT trap (core dumped)

So, for some reason it can't find the stuff inside the static library. Oddly, I am linking the static library into the shared library when I build the shared library, so I don't understand why the static library call isn't able to be located by JNI......

Am I missing something? :-)
2 REPLIES 2
David Calkins_2
Occasional Contributor

Re: Unresolved Symbol when calling C code via JNI

Some more digging has revealed the following.

If I build an executable, which calls the shared library, which in turn calls the static library, I have to link in the static library with the executable itself. i.e. its not enough to link the static library into the shared library.

The problem now is that with JNI, there is no executable. The JVM is directly calling the shared library. So how do I get the static library "stuff" into the shared library so that it can be used indirectly by the JVM via JNI?

Re: Unresolved Symbol when calling C code via JNI

Dave,

are you trying to mix static and shared libraries (.sl and .a files)? aCC discourages that. Quote from aCC documentation:

NOTE: To maintain compatibility on future releases, archive and shared libraries should not be mixed. Refer to the "Mixing Shared and Archive Libraries" section in the HP-UX Linker and libraries Online User Guide.

Regards, Martin