Solved

jni and static libraries

Posted on 1997-10-14
4
839 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add projects t working set in maven 2 44
java imports not found 4 51
JDBC performance 8 29
Pass multiple values or string arrays in java as a parameter 3 46
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

733 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