Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

jni and static libraries

Posted on 1997-10-14
4
Medium Priority
?
860 Views
Last Modified: 2013-12-14
I'm writing a Java application that calls some functions in a static
library on Solaris 2.4.  A shared library libMyShared.so is created to
call functions in the static library libMyStatic.a: CC -G test.c -o
libMyShared.so -lMyStatic where test.c implements the native calls. When
I run the Java application, I get the following error: ld.so.1:
/usr/local/jdk1.1.1/bin../bin/sparc/green_threads/java: fatal: relocation
error: symbol not found: __0oNIostream_initctv: referenced in
 ./libMyShared.so killed

Does anyone know what is happening?
Thanks in advance for any advice/suggestions.

Jun
jz4349@sbc.com
0
Comment
Question by:jz4349
4 Comments
 
LVL 6

Expert Comment

by:jpk041897
ID: 1228602
Sounds like your getting a conflict between static and shared instances of a function.

When you compile a library, you will be using either static or shared instances of the standard UNIX libs. When you attempt to link them both together in a single app. Your linker will most likley get totaly confused.

For this kind of mix, I would suggest you use CORBA or RPC's to establish the communication with functions that will make the calls to the static library, thus avoiding the presence of duplicated static/dynamic symbols.





0
 

Accepted Solution

by:
fakir earned 100 total points
ID: 1228603
Making a C interface to a C ++ package is not so easy, if
you are using C++ predefined object is not so easy. The C
entry point should initialize C++ static objects such as IO objects (cin, cout, cerr, and more)

I say that when I see iostream references that should require something that libC++ in the library compile & link line

I think the problem is in your C native library where C++ static objects are undefined. If you build a C main program which uses
C++ libraries that use C++ static objects, you'll have to call special code that allow you to create and init those objects.

Hope this helps

Gilles

0
 

Author Comment

by:jz4349
ID: 1228604
The expert may be right, but no specific solution is suggested.
Adding "/usr/lib/libC.so.5" to the compile line solved the problem
(Thanks to qtxchho@aom.ericsson.se )
0
 

Expert Comment

by:preetiaggarwal
ID: 4427434
Hi,

I am writing a java program which uses JNI to call old c++ libraries, and got error message:

ld.so.1:jdk/bin/sparc/native_threads/java:fatal relocation error:file /home/myhome/lib/libtest.so: symbol __xxxxx: referenced symbol not found

libtest.so is the shared library called indirectly by the java program. __xxxxx is the symbol of the function which is called in libtest.so and is defined in another library libcalledtest.so.

Both libraries libtest.so and lbcalledtest.so are in the same directory which is in LD_LIBRARY_PATH.

I am using SunOS 5.5.1, java 1.2.2 and SC++ 4.2. Please send response to preetia@ggn.hcltech.com.

thanks
  preeti
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question