"Aaron M. Stromas" wrote:
> 
> greetings,
> 
> I need a little assistance with building a shared library for JNI under
> Linux 2.2.
> This is how I went about creating the library:
> 
> compiling: g++ -I /usr/local/java/include
> -I/usr/local/java/include/linux -shared -fPIC -o keys.o keys.c
> 
> linking: gcc -shared -Wl,-soname,libkeys.so -o libkeys.so.0 keys.o -lc
> 
> $ java -Djava.library.path=/home/ams/work/keys T
> Exception in thread "main" java.lang.UnsatisfiedLinkError: 
>/home/ams/work/keys/libkeys.so: keys.o: cannot open shared object file: No such file 
>or directory
>         at java.lang.ClassLoader$NativeLibrary.load(Native Method)
>         at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1357)
>         at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1281)
>         at java.lang.Runtime.loadLibrary0(Runtime.java:469)
>         at java.lang.System.loadLibrary(System.java:774)
>         at T.<clinit>(T.java:5)
> 
> I have also tried another way of building the library (ld -G -f
> /lib/libuuid.so.1 keys.o -o libkeys.so) but got the same error. I have
> to mention that the native code accesses the libdb.so library which i
> copied to /home/ams/work/keys. Why doesn't java find my library? TIA,

I found that JNI code can compile and link without error and still be
incorrect, and the only error you do get is the one above.  I diagnose
this with 'ldd -r /path/to/library/file' and see if there are any
unresolved references that don't point to an existing library.

Your library is looking for a routine "keys" which does not exist in
that library, or any of the other .o files you sent through the linker.

Here's bits of a Makefile with the gcc/library commands I use:

JAVA_HOME=/usr/local/java/jdk1.2.2
JAVA_INC= -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux                          
 #
# gcc configurable compile options of interest
# -H list include header names
# -g debugging code enabled
GCCOPT= -g
LDOPT=-Xlinker -t -Xlinker -Map -Xlinker /tmp/linkmap
GCCDEF=-DIP_SUPPORT -DUNIX
LIBOUT=$(HOME)/lib 
SRC=$(PROJ)/src       
                                                                                       
                                                                                       
                                                                                       
                                                     
$(LIBOUT)/libjsystem.so: \
  $(SRC)/JNsApiSubsystemInterfaces.h \
  $(SRC)/JNsApiSubsystemInterfaces.c \
  $(CLASSES)/com/aravox/nsapi/subsystem/JNsApiSubsystemInterfaces.class
        - rm -f $@
        @echo Creating $@...
        gcc $(GCCOPT) $(GCCDEF) $(JAVA_INC) -I$(SRC) \
          $(LDOPT) \
          -shared -o $@ $(SRC)/JNsApiSubsystemInterfaces.c \
          $(LIBOUT)/lib*.so
        /home/joi/bin/anyUndefined $(LIBOUT)/lib*.so
  

anyUndefined is a bash script which inspects the resulting .so for 
unresolved references and exits with an error code make will detect.
                                                                                       
                                      
#!/bin/bash
tmp=/tmp/anyUndefined.$$
ldd -r $1 >$tmp  2>&1
echo "----------"
cat $tmp
echo "----------"
if
  grep undefined $tmp;
then
  exit 1
else
  exit 0
fi                                                                                     
                                        


--
Joi Ellis                    Software Engineer
Aravox Technologies          [EMAIL PROTECTED], [EMAIL PROTECTED]

No matter what we think of Linux versus FreeBSD, etc., the one thing I
really like about Linux is that it has Microsoft worried.  Anything
that kicks a monopoly in the pants has got to be good for something.
           - Chris Johnson


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to