Operating System - Linux
1753777 Members
7330 Online
108799 Solutions
New Discussion юеВ

Error loading shared library from Java application

 
SOLVED
Go to solution
Marc Theisen
Occasional Advisor

Error loading shared library from Java application

Trying to load a shared library that was compiled with g++/gcc inside a Java application (using JNI) fails with the following error message:

aCC runtime: Use of "-mt" must be consistent during both compilation and linking.

Even though aCC is installed on the machine I do not understand why its runtime libraries are used. Do I need to deinstall the native compiler again? gcc (version 4.2.3) was installed after aCC.

Is there any g++/gcc option I am missing here? I am only using -fPIC and -shared for the linker step.

Thanks in advance!
Marc
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: Error loading shared library from Java application

Marc Theisen
Occasional Advisor

Re: Error loading shared library from Java application

This article describes an issue with the aCC compiler. But I am not using this compiler. In fact I have deinstalled it from the machine and still get the same error message. Removing the dependency on libpthread.so did not help either.

Here is the output of the ldd command on the .so that is loaded from the Java side:

libstdc++.so => /usr/local/lib/libstdc++.so
libunwind.so.1 => /usr/lib/hpux32/libunwind.so.1
libm.so.1 => /usr/lib/hpux32/libm.so.1
libc.so.1 => /usr/lib/hpux32/libc.so.1
libstdc++.so => /usr/local/lib/gcc/ia64-hp-hpux11.31/4.2.3/../../../libstdc++.so
libm.so.1 => /usr/lib/hpux32/libm.so.1
libc.so.1 => /usr/lib/hpux32/libc.so.1
libuca.so.1 => /usr/lib/hpux32/libuca.so.1
libdl.so.1 => /usr/lib/hpux32/libdl.so.1

Any help is highly appreciated!
Marc
Dennis Handly
Acclaimed Contributor

Re: Error loading shared library from Java application

As mentioned in the other link, your JNI has not been compiled with the aCC's -mt option.
Since Java is compiled with aC++, you will not be able to have a JNI compiled with g++, just gcc.
What OS version and what type of hardware do you have? Do you get a core file?
Marc Theisen
Occasional Advisor

Re: Error loading shared library from Java application

Hi Dennis,

So you are saying I cannot link any modules that were generated with g++ because the JVM libraries were (at least partially) compiled with aCC ? That's bad since most of our code is written in C++, not C. So that actually means I need to use aCC/cc to create the .so files in order to load them from Java using System.loadLibrary(). I will then try to do the port using the native compiler, then.

Thanks for your help!
Marc
Dennis Handly
Acclaimed Contributor
Solution

Re: Error loading shared library from Java application

>So you are saying I cannot link any modules that were generated with g++ because the JVM libraries were (at least partially) compiled with aCC?

Yes though I've never seen that error symptom before.

>So that actually means I need to use aCC/cc to create the .so files in order to load them from Java using System.loadLibrary().

Yes.