Operating System - HP-UX
1752588 Members
4279 Online
108788 Solutions
New Discussion

Problem with Java JNI Java and C

 
curious7
New Member

Problem with Java JNI Java and C

Hi,

 

I need a Java program to call a C program (not C++).  I’m following the instructions on HP-UX Programmer's Guide for Java™ 2. However, it doesn’t work. Here are the Java and platform versions:

 

$uname –mr

B.11.31 ia64

 

java –version

java version "1.6.0.11"

Java(TM) SE Runtime Environment (build 1.6.0.11-jinteg_14_jul_2011_03_07-b00)

Java HotSpot(TM) Server VM (build 20.1-b02-jre1.6.0.11-rc2b1, mixed mode)

 

It compiles and builds the library fine and I do set SHLIB_PATH to the directory of the library. I compile:

cc -Ae +u4 +z -c -D_HPUX \

> -I/opt/java6/include -I/opt/java6/include/hp-ux -I./ \

>  myProg.c

 

And build the shared lib as either:

aCC -b -o myProg.so myProg.o \

-lstd -lstream -lCsup -lm

 

(tried it also with cc)

 

Or as:

ld -b -o myProg.so myProg.o

 

And tried some other options. But always when I run the Java program that calls this C program I get:

java.lang.UnsatisfiedLinkError: no myProg in java.library.path

 

Can someone point the exact compile and library build commands for this platform and Java version? I did test the Java Property and verified the directory of the shared library is there.

 

Thanks.

 

1 REPLY 1
Dennis Handly
Acclaimed Contributor

Re: Problem with Java JNI Java and C

>And build the shared lib as either:

aCC -b -o myProg.so myProg.o -lstd -lstream -lCsup -lm

 

This is incorrect, I thought I got them to change it.

For Integrity, -AA:

aCC -b -o libmyProg.so myProg.o -lstd_v2 -lCsup -lunwind -lm 

 

>(tried it also with cc)

 

You shouldn't really be using ld:

cc -b -o libmyProg.so myProg.o

 

>Can someone point the exact compile and library build commands for this platform and Java version?

 

I think the key point is that you have to have the "lib" prefix and the ".so" suffix.

I'm not sure what step needs the "export CLASSPATH=..."?