Makefile for .so

Makefile for .so

Post by R Ghosh-R » Fri, 28 Feb 1997 04:00:00



I have searched everywhere to find some kind of help to create a
.so (shareable object) file as we see in SunOS /usr/lib/lib*.so.*

I tried various ways to modify my Makefile to achieve this but
haven't succeeded yet. I am therefore asking for your help. I
am aware of the fact that not many programmers create a .so file
and hence this question may not be in any FAQ.

The following was my best shot:

CC = /vol/PACK/SunPro.4/acc -sys5 -Xc \
                            -D_POSIX_SOURCE -DFUNCPROTO -D_XOPEN_SOURCE -w
#
# ========== .so: shared object library==========

CFLAGS = -I./ \
         -I/vol/PACK/SunPro.3/SC3.0.1/include/cc_413_U1 \
         -I${MOTIFHOME}/include \
         -I/usr/xpg2include

CFLAGSX = -L${MOTIFHOME}/lib \
          -L${II_SYSTEM}/ingres/lib \
          -lingres \
          -lMrm -lXm -lXt -lX11 -lF77 -lM77 \
          -ll -ly -lm

# ========== libraries and headers ==========
MACHINE = SUN

LIB_DIR    = .
OBJ_DIR    = .

LIB        = library.so

SOURCES  = \
        program_x.c \
        programclilib.c \
        programapplib.c
OBJECTS  = \
        program_x.o \
        programclilib.o \
        programapplib.o

$(LIB_DIR)/$(LIB): $(LIB_DIR)/$(LIB).1
        rm -f $(LIB_DIR)/$(LIB); ln -s $(LIB_DIR)/$(LIB).1 $(LIB_DIR)/$(LIB)

$(LIB_DIR)/$(LIB).1: $(OBJECTS:%=$(OBJ_DIR)/%)
        $(CC) -G -h $(LIB_DIR)/$(LIB).1 $? -o $(LIB_DIR)/$(LIB).1

$(OBJ_DIR)/%: $(SOURCES)

clean:
        rm -f $(OBJECTS:%=$(OBJ_DIR)/%) $(LIB_DIR)/$(LIB) $(LIB_DIR)/$(LIB).1

If you already a sample Makefile for .so, please e-mail it to me if that's
not inconvenient for you.

Thanks,

Rana

--

--

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 
 
 

Makefile for .so

Post by Frank Pilhof » Fri, 28 Feb 1997 04:00:00



>I tried various ways to modify my Makefile to achieve this but
>haven't succeeded yet. I am therefore asking for your help. I
>am aware of the fact that not many programmers create a .so file
>and hence this question may not be in any FAQ.

 Few people use shared libraries because it is a very system-specific
task, and folks who want their packages to be portable start running
into major problems sooner or later.
 However, on SunOS 5.x it's quite simple.
 Add the "-KPIC" option to the compiler, and later link using
   /usr/ccs/bin/ld -G -z text -o libwhatever.so x.o y.o ...

 At least that's the way Tcl suggests ...

        Frank

--

 |                                      http://www.uni-frankfurt.de/~fp/ |
 +---- Life would be a very great deal less weird without you.  - DA ----+

 
 
 

Makefile for .so

Post by Casper H.S. Dik - Network Security Engine » Tue, 04 Mar 1997 04:00:00



> Few people use shared libraries because it is a very system-specific
>task, and folks who want their packages to be portable start running
>into major problems sooner or later.
> However, on SunOS 5.x it's quite simple.
> Add the "-KPIC" option to the compiler, and later link using
>   /usr/ccs/bin/ld -G -z text -o libwhatever.so x.o y.o ...

It works, *but* you really should use your C compiler to do the task.

E.g., if you where to relink the Solaris C library with ld, your
stdio files are no longer flushed because flusing is done in the
libraries .fini section. (Which incidentally has the benefit of
making exit() not pull in all flsbuf code when linking statically)

This is especially importan for C++ code w/ static constructors/destructors.

So in SunOS 5.x, you'd use:

        cc -G -o libfoo.so .....
    or
        gcc -shared -o libfoo.so ......

and for C++

        CC -G ..
    or

        g++ -shared ...

BTW, don't use "-G" w/ gcc, use -shared instead.  Otherwise you'll end
up with a "main undefined" in each shared object.

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.