Forum Stats

  • 3,853,789 Users
  • 2,264,269 Discussions
  • 7,905,445 Comments

Discussions

how to dynamicaly link multiple shared objects (.so files) using JNI

843829
843829 Member Posts: 49,201
edited Sep 15, 2010 3:14PM in Java Native Interface (JNI)
Hi all,
I recently started working on JNI where i suppose to call C application's .so files using JAVA. Existing C application is huge, it contains many .so files which are having dependencies with other .so files. My problem is when i call a function of one .so file it does not link with other .so files at run time and gives me error(undefined function as that function is implemented in other .so file).
Can someone suggest me any solution for the same? I am a Java developer and don't have much knowledge about the C language.
Any suggestion will be highly appreciated.

Comments

  • jschellSomeoneStoleMyAlias
    jschellSomeoneStoleMyAlias Member Posts: 24,877 Gold Badge
    jeet420 wrote:
    Hi all,
    I recently started working on JNI where i suppose to call C application's .so files using JAVA. Existing C application is huge, it contains many .so files which are having dependencies with other .so files. My problem is when i call a function of one .so file it does not link with other .so files at run time and gives me error(undefined function as that function is implemented in other .so file).
    That is not a Java/JNI problem.

    A shared library either uses an explicit link or dynamic link to other libraries.
    If the first then the OS will fail the load of the library if it can't find the dependency.
    If the second then the implementation (the developer) is responsible for correctly dealing with the problem.

    Again none of the above has anything to do with Java nor JNI.
    Nothing in Java nor JNI will help you to figure out the problem nor manage it.

    Two solutions.
    1. Be very careful in manually managing the laydown via an installer of all of the required libraries.
    2. Write code to verify that all libraries are found by the OS. This however still require manual steps as you must explicitly name the shared libraries in some way.
    ... and don't have much knowledge about the C language.
    Not a good situation. JNI assumes that you have quite a bit of knowledge about C and/or C++.
  • jschellSomeoneStoleMyAlias
    jschellSomeoneStoleMyAlias Member Posts: 24,877 Gold Badge
    Note that you can use Java either via System.load() or System.loadLibrary() to load any shared library, it doesn't have to be just JNI ones.

    You could use that, with the correct ordering of the shared libraries, to insure that all of the needed dependent libraries were present.
This discussion has been closed.