Solved

jni and static libraries

Posted on 1997-10-14
4
840 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

717 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