Solved

jni and static libraries

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
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:
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now