Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Linux JVM: How to load shared libraries with mutual/circular dependencies

843829May 10 2004 — edited May 13 2004
Hi,

I am using the API

System.loadLibrary(String name)

to dynamically link shared libaries to Linux JVM.

The shared libraries has complex circular symbol dependencies among them.
I am not able to load shared libraries due to java.lang.UnsatisfiedLinkError.

Any ideas on how a number of shared libraries with interdependent realtionships
could be successfully linked in to the Linux JVM?

Thanks,
Soumen.

Background
===========
Successful execution of native code within Java virtual machine in a
host platform, has two necessary prerequisites:

Prerequisite 1: The native code is written to the JNI specification

Prerequisite 2: The native code is dynamically linked with Java virtual
machine.

The second step is achieved via simple Java interface, System.loadLibrary:

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#loadLibrary(java.lang.String)

However, implementation of this interface is highly platform dependent
in regards to exact nature of dynamic linking process.

Tests
=====
I made three shared libraries libfeatureA.so, libfeatureB.so and libfeatureC.so.
Feature A and Feature B are mutually dependent on each other (i.e cicular
dependencies between libfeatureA.so, libfeatureB.so) whereas libfeatureC.so
has no external dependencies.

Case 1
--------
I could link libfeatureC.so with java.

Case 2
--------
Java failed to resolve circular dependency between libfeatureA.so, libfeatureB.so
resulting in linking failure. There may be repackaging workarounds which I have
not yet explored.

Java source code
================
class TestLoadLibrary
{
static
{
System.loadLibrary("featureB");
System.loadLibrary("featureA");
System.loadLibrary("featureB");
}

public static void main(String[] args)
{
System.out.println("In TestLoadLibrary.main()");
}
}

Exception in thread "main" java.lang.UnsatisfiedLinkError: /homes/soumen/work/event/featureB/libfeatureB.so.1.0: /homes/soumen/work/ev B.so.1.0: undefined symbol: featureA_func2
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1737)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1662)
at java.lang.Runtime.loadLibrary0(Runtime.java:817)
at java.lang.System.loadLibrary(System.java:986)
at TestLoadLibrary.<clinit>(TestLoadLibrary.java:5)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 10 2004
Added on May 10 2004
7 comments
3,085 views