Hi,
Can i load more than one library in jni? I have 4 lib used in my program:
System.loadLibrary("pthread");
System.loadLibrary("util");
System.loadLibrary("cops");
System.loadLibrary("COPS");
and i 've got this error msg when i run my program
Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/kw
ong/thesis/codes/libutil.so: /home/kwong/thesis/codes/libutil.so: undefined symbol:
pthread_cond_timedwait
Kason
Joi Ellis wrote:
> On Sun, 29 Oct 2000, kason wong wrote:
>
> > hi,
> >
> > I'm not sure this is the mail-list i should send my question. please
> > let me know if I've got the right place.
> >
> > my problem is in the compiling a function in c++ to a .so lib file. the
> > case is I use a couple static .a lib in that c++ program and when i
> > compile it to a .so lib. it doesn't include the .a lib in it. i guess
> > that's why I always get "undefined symbol" error when i execute the java
> > program which call the c++ function.
> >
> > what can i do ? hope someone can give me some help here.
>
> Here's a makefile I use for compiling a jni layer which
> calls routines in *.a files. libsystem.a is the original library.
> This gets converted to libsystem.so for use in the link step.
> The final loadable library is libjsystem.so.
>
> JNsApiSubsystemInterfaces.c and .h are the C JNI layers connecting
> JNsApiSubsystemInterfaces.java to libsystem.o to become libjsystem.so.
>
> Pay particular attention to the a.so suffix rule, and the sequence of
> commands for building libjsystem.so toward the bottom. The ld and gcc
> options are particularly important. The -shared is the key gcc option
> and as such is hardwired in the command rather than being stored in
> GCCOPT.
>
> I use gcc, not g++, but the methods should be close to identical.
> There may be other ways of doing this, but this is what I found works well
> on my Red Hat system.
>
> -------------------------------------------------------------------------
> .SUFFIXES : .h .c .a .so .java .class
>
> .a.so:
> ld -shared -o $*.so --whole-archive $<
> nm $*.so >$*.symbols
>
> .java.class:
> true
>
> #
> # location of JVM we're linking to
> #
> # Sun's 1.2.2
> #
> JAVA_HOME=/usr/local/java/jdk1.2.2
> JAVA_INC= -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
> JAVAH=/usr/local/java/jdk1.2.2/bin/javah
>
> #
> # gcc configurable compile options
> # -H list include header names
> # -g debugging code enabled
> GCCOPT= -g
> LDOPT=-Xlinker -t -Xlinker -Map -Xlinker /tmp/linkmap -Xlinker -cref
> GCCDEF=-DIP_SUPPORT -DUNIX
> #
> # Where the library.so file is written
> #
> LIBOUT=$(HOME)/lib
> #
> # These start as .a files, I have to convert them to
> # shareable .so files for JNI to access them.
> #
> JAPILIBS=$(LIBOUT)/libjsystem.so
>
> APISOLIBS= $(LIBOUT)/libsystem.so
>
> APILIBS= $(LIBOUT)/libsystem.a
>
> LINKLIBS=-L$(LIBOUT) -lnat -lsystem -ludpmsg -luser -lvoip -lc
> #
> # Project's root directory
> #
> PROJ=$(HOME)/jbproject/NSApi
> #
> # Project's source root and classpath root
> #
> SRC=$(PROJ)/src
> CLASSES=$(PROJ)/classes
> #
> # base name of the library
> #
> LIBNAME=jsubsystem
> #
> # C Source files for gcc command
> #
> CSRC=$(SRC)/JNsApiSubsystemInterfaces.c
> #
> # Java Class files
> #
> JCLASSES= $(CLASSES)/com/aravox/nsapi/*.class \
> $(CLASSES)/com/aravox/nsapi/subsystem/*.class
> #
> # all sources lib depends upon
> #
> ALLSRC= $(SRC)/*.h $(SRC)/*.c $(JCLASSES)
>
> all: $(APISOLIBS) $(JAPILIBS) $(ALLSRC)
>
> $(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
>
> $(SRC)/JNsApiSubsystemInterfaces.h:
>$(SRC)/com/aravox/nsapi/subsystem/JNsApiSubsystemInterfaces.java
> - ls -lart $(SRC)/com/aravox/nsapi/subsystem/JNsApiSubsystemInterfaces.java
>$(SRC)/JNsApiSubsystemInterfaces.h $(SRC)/JNsApiSubsystemInterfaces.h
> $(JAVAH) \
> -classpath $(CLASSES) \
> -o $(SRC)/JNsApiSubsystemInterfaces.h \
> com.aravox.nsapi.subsystem.JNsApiSubsystemInterfaces
> echo "$(SRC)/JNsApiSubsystemInterfaces.h regenerated";
>
> $(SRC)/com/aravox/nsapi/JNsApiSubsystemInterfaces.java:
> @echo "Nothing to do."
>
> clean:
> rm -f $(LIBOUT)/*.so
> rm -f $(SRC)/JNsApiSubsystemInterfaces.h
>
> -------------------------------------------------------------------------
> --
> 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]
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]