Operating System - HP-UX
1825822 Members
2956 Online
109688 Solutions
New Discussion

JNI compilation/linking issues on an HP-UX IA64 using gcc

 
nallamolu
Advisor

JNI compilation/linking issues on an HP-UX IA64 using gcc

Hi World,

1.) Can anyone provide me with the command line arguments that would be required to compile and link JNI 'c' code in 64bit mode using gcc ?

Compiler: gcc-hppa64-4.3.1.depot
Java : jdk6_16002_pa.depot
OS : IA64 11.23

2.) What are the Options we need to set for
compiling the java code in 64 bit mode.
14 REPLIES 14
Dennis Handly
Acclaimed Contributor

Re: JNI compilation/linking issues on an HP-UX IA64 using gcc

>Java: jdk6_16002_pa.depot, OS: IA64 11.23

(I'm not sure why you have "_pa" when you are on IPF?)

Basically you need to compile in 64 bit mode: -mlp64

And run java with -d64.
nallamolu
Advisor

Re: JNI compilation/linking issues on an HP-UX IA64 using gcc

Hi World,

I have used jdk6_16002_ia.depot for IA64 not the PA_RISC jvm ( It was a typing mistake ).

I compiled the JNI 'c' code in 64bit mode using gcc options:

GCC Compiling options as
gcc -fPIC -mlp64 -D_REENTRANT

GCC Linking Options as
gcc -lc -shared

I invoked the 64 Bit JVM using
-d64

While compiling i got the error as

[jnicc] ** COMPILER: ld: Mismatched ABI for -lgcc_s, found /opt/hp-gcc-4.3.1/lib/gcc/ia64-hp-hpux11.23/4.3.1/../../../libgcc_s.so

[jnicc] ** COMPILER: Fatal error.

[jnicc] ** COMPILER: collect2: ld returned 1 exit status

Error while executing gcc -g -lc -shared -o /tmp/nalgo01/libStats.so /tmp/nalgo01/compiler/hpuxmonitor/java_interface.o


I would appreciate any help on this

Thanks in Advance
Gopinath
Dennis Handly
Acclaimed Contributor

Re: JNI compilation/linking issues on an HP-UX IA64 using gcc

>gcc linking options as: gcc -lc -shared

You forgot the most important option, -mlp64. Also leave -lc off all link lines.
nallamolu
Advisor

Re: JNI compilation/linking issues on an HP-UX IA64 using gcc

Hi Dennis,

As u have said i have used the gcc linking options as

GCC Linking Options as
gcc -mlp64 -shared

It got compiled sucessfully.

I used the generated .jar and .so files in my application and it produced the following error

java.lang.UnsatisfiedLinkError: Can't load library: /tmp/nalgo01/Probeing/libStats.so
java.lang.ClassLoader.loadLibrary(ClassLoader.java:1650)
java.lang.Runtime.load0(Runtime.java:770)
java.lang.System.load(System.java:1005)


I would appreciate any help on this

Thanks in Advance
Gopinath
Dennis Handly
Acclaimed Contributor

Re: JNI compilation/linking issues on an HP-UX IA64 using gcc

>java.lang.UnsatisfiedLinkError: Can't load library: /tmp/nalgo01/Probeing/libStats.so

This isn't helpful, it should print the unsatisfied symbol.

Can you relink with -lc and retry? I don't think it will fix it but it will make the nm(1) list below smaller.

Can you provide:
nm -px /tmp/nalgo01/Probeing/libStats.so | grep " U "
nallamolu
Advisor

Re: JNI compilation/linking issues on an HP-UX IA64 using gcc

Hi Dennis,

linked With out -lc option

$ nm -p -x libIntroscopeHPUXItanium64Stats.so | grep " U "

0x0000000000000000 U atoi
0x0000000000000000 U free
0x0000000000000000 U getpid
0x0000000000000000 U getppid
0x0000000000000000 U getrusage
0x0000000000000000 U malloc
0x0000000000000000 U pstat_getdynamic
0x0000000000000000 U pstat_getprocessor
0x0000000000000000 U sysconf


linked With -lc option

$ nm -p -x libIntroscopeHPUXItanium64Stats.so | grep " U "

0x0000000000000000 U atoi
0x0000000000000000 U free
0x0000000000000000 U getpid
0x0000000000000000 U getppid
0x0000000000000000 U getrusage
0x0000000000000000 U malloc
0x0000000000000000 U pstat_getdynamic
0x0000000000000000 U pstat_getprocessor
0x0000000000000000 U sysconf

Both are producing the same result.

Does i need to set any ld or shlib path

Thanks in Advance
Gopinath
Dennis Handly
Acclaimed Contributor

Re: JNI compilation/linking issues on an HP-UX IA64 using gcc

>U atoi ...
>U sysconf

These all should be defined in libc.

>linked With -lc option

Oops, that's linked with -lc and -Wl,+vshlibunsats

(So, you don't need nm(1).)

>Do I need to set any ld or shlib path?

No. I don't know if using -Wl,-Bverbose may help?
Have you looked at the java JNI documentation to see if there are specific symbols that must be defined?
nallamolu
Advisor

Re: JNI compilation/linking issues on an HP-UX IA64 using gcc

> Oops, that's linked with -lc and -Wl,+vshlibunsats

can u please explain what it means

1.) Does using these options in linking helps
-Wl,+vshlibunsats

> No. I don't know if using -Wl,-Bverbose may help?

shall i use these options -Wl,-Bverbose as linker arguments

> Have you looked at the java JNI documentation to see if there are specific symbols that must be defined?

specific symbol means.. what kind of symboles

I would appreciate any help on this

Thanks in Advance
Gopinath
Dennis Handly
Acclaimed Contributor

Re: JNI compilation/linking issues on an HP-UX IA64 using gcc

>1.) Does using these options in linking help -Wl,+vshlibunsats

No. They just will list the symbols that aren't defined in your shlib. Which I assumed was the cause of your java UnsatisfiedLinkError.

>shall I use these options -Wl,-Bverbose as linker arguments?

Yes, that may cause dld.so to print more verbose errors.

>specific symbol means. what kind of symbols?

Specific names.
Dennis Handly
Acclaimed Contributor

Re: JNI compilation/linking issues on an HP-UX IA64 using gcc

Here is the JNI documentation. You might try out the sample first:
http://docs.hp.com/en/JAVAPROGUIDE/JNI_java2.html#java_native_c
nallamolu
Advisor

Re: JNI compilation/linking issues on an HP-UX IA64 using gcc

Hi Dennis,

I have gone through the link which u have send
> http://docs.hp.com/en/JAVAPROGUIDE/JNI_java2.html#java_native_c

In this link i found a statement which states as follows...
""
On Integrity, create the shared library using:

$ aCC -b -o libaCCImpl.so aCCImpl.o \
-lstd_v2 -lCsup -lunwind -lm

On Integrity, the -AA lib -lstd_v2 is necessary, otherwise, running the program will result in UnsatisfiedLinkErrors.

""

Does we have an option -lstd_v2 in gcc.
Where we need to include this option ie in compilation or linking.

In advance i wish u Very Happy New Year

Regards,
Gopi
Dennis Handly
Acclaimed Contributor

Re: JNI compilation/linking issues on an HP-UX IA64 using gcc

>I found a statement which states as follows ... running the program will result in UnsatisfiedLinkErrors.

This should be for aC++ only, not C.

>Do we have an option -lstd_v2 in gcc?
>Where we need to include this option ie in compilation or linking.

This is a link option but I can't see how it would make it work, since you don't have any unsats.
What are the names of your native methods and are they in your shlib?
nm -px libIntroscopeHPUXItanium64Stats.so | grep " [TBD] "
nallamolu
Advisor

Re: JNI compilation/linking issues on an HP-UX IA64 using gcc

Hi Dennis,

> nm -px libIntroscopeHPUXItanium64Stats.so | grep " [TBD] "

$ nm -px libIntroscopeHPUXItanium64Stats.so | grep " [TBD] "
0x4000000000001ca0 T JNU_ThrowByName
0x4000000000003000 T Java_com_hpux_HPUXPlatformStatisticsBackEnd_getAggregateCPUUsage
0x4000000000001ea0 T Java_com_hpux_HPUXPlatformStatisticsBackEnd_getCPUIndexMap
0x4000000000002ee0 T Java_com_hpux_HPUXPlatformStatisticsBackEnd_getParentProcessID
0x40000000000023a0 T Java_com_hpux_HPUXPlatformStatisticsBackEnd_getProcessCPUUsage
0x4000000000002dc0 T Java_com_hpux_HPUXPlatformStatisticsBackEnd_getProcessID
0x4000000000002d50 T Java_com_hpux_HPUXPlatformStatisticsBackEnd_getProtocolVersion
0x4000000000003be0 T Java_com_hpux_HPUXPlatformStatisticsBackEnd_getThreadCpuTime
0x40000000000025e0 T Java_com_hpux_HPUXPlatformStatisticsBackEnd_getTotalClockTicks
0x4000000000002d80 T Java_com_hpux_HPUXPlatformStatisticsBackEnd_init
0x4000000000003bb0 T Java_com_hpux_HPUXPlatformStatisticsBackEnd_isThreadCpuTimeEnabled
0x4000000000002da0 T Java_com_hpux_HPUXPlatformStatisticsBackEnd_term
0x40000000000002b0 D _DYNAMIC


1.) What are the compiling options for aCC(aC++) to compile in 64 bit mode ( HP-UX IA64 ).
Is it +DD64

> What are the names of your native methods and are they in your shlib?

The names of the native methods u can see above.

Does we nee to set shlib path. if yes to which location we need to set.
Dennis Handly
Acclaimed Contributor

Re: JNI compilation/linking issues on an HP-UX IA64 using gcc

>1) What are the compiling options for aCC(aC++) to compile in 64 bit mode? Is it +DD64

Yes.

>The names of the native methods you can see above.

How are they declared in java?
Is this some class name? Java_com_hpux
What is JNU_ThrowByName for?

>Do we need to set SHLIB_PATH?

No, you aren't using any other shlibs.

I suppose you could use gdb to see what dl* functions are being called, dlopen, dlsym.