?
Solved

jni and static libraries

Posted on 1997-10-14
4
Medium Priority
?
848 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
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 …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month13 days, 8 hours left to enroll

800 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