On Mon, 30 Oct 2000, kason wong wrote:

> I guess I finally understand. but i still have problem in compiling one lib: 
>libutil.so which
> used the libpthread.a lib in c. I try to convert libpthread.a to .so, it seems 
>strange but
> when i load it:
> 
> ld -shared -o libpthread.so --whole-archive /local/usr/lib/libpthread.a
> ldd -r libpthread.so
>         statically linked
> 
> I think this is the main problem when i convert libutil.a to libutil.so and i try to 
>load
> libutil.so

Where is libutil.a coming from?  if that's your code, then you aren't linking
it properly.  Convert any lib*.a files it depends upon to lib*.so, then use
the g++ -shared -o libutil.so command to create it.  Then ldd -r libutil.so
and make sure it found everything it needed.  If it didn't, add the missing
library to the g++ command and try again until it finds every symbol it needs.
Then you will be able to loadLibrary("util") and see it work.

If you're creating a .a file, by definition that doesn't include all the
dependent routines.

Here's my entire Makefile.  It has exactly the stuff you need, I suggest
you use a copy of it and edit appropriately.  Mass-replace libjsystem.so
with your libutil.so.  Stick -lpthread into LINKLIBS.  Stuff in LINKLIBS
is system libs which already have *.so files.  Edit paths to refer to your
directories instead of mine.

Any libs you possess which are only in lib*.a form should be placed
in APILIBS.  Put their *.so forms in APISOLIBS.  Place your final
library, libutil.so, in JAPILIBS.  Then edit the build rule for
libjsystem.so to name it libutil.so, and adjust the *.c and *.h filenames
appropriately.  Don't change anything else on the line.

I've also attached my bash script which returns an error code if the ldd -r
command returns undefined errors.  That causes make to stop and whine
if the build fails, otherwise make doesn't know it's a bad build.

------------------------------------------------------------------------
.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
#
# Carol's C api libraries in their converted form
# These start as .a files, I have to convert them to
# shareable .so files for JNI to access them.
#
JAPILIBS=\
  $(LIBOUT)/libjsystem.so 
#  $(LIBOUT)/libjnat.so \
#  $(LIBOUT)/libjudpmsg.so  \
#  $(LIBOUT)/libjuser.so  \
#  $(LIBOUT)/libjvoip.so

APISOLIBS=$(LIBOUT)/libnat.so \
  $(LIBOUT)/libsystem.so  \
  $(LIBOUT)/libudpmsg.so  \
  $(LIBOUT)/libuser.so  \
  $(LIBOUT)/libvoip.so

APILIBS=$(LIBOUT)/libnat.a \
  $(LIBOUT)/libsystem.a  \
  $(LIBOUT)/libudpmsg.a  \
  $(LIBOUT)/libuser.a  \
  $(LIBOUT)/libvoip.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) $(CLASSES)/md5_sha1

$(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."


------------------------------------------------------------------------
-- 
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
#!/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

Reply via email to