🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c++.leda
Article #177

Re: Shared Library under Solaris

#177
From: Olivier L'Heureux
Date: Mon, 12 Feb 1996 11:55
594 lines
17788 bytes
--Multipart Mon Feb 12 12:54:19 1996
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit

In article <ROADHOZF.96Feb2141851@sun16.engin.brown.edu>
roadhozf@sun16.engin.brown.edu (z.f roadhouse) writes:

>> I seem to remember that someone had instructions for create LEDA's
>> libraries as shared libs under Solaris.  If you know how to do
>> this, could you post instructions?

Yes. Here is the message I posted on the 31st of October, 1995.
Please drop me a message if you succeed or if you have problems.
BTW, I putted a copy of the original message on

  <URL:ftp://ftp.dice.ucl.ac.be/pub/divers/leda-shared.gz> (5 KB)

						Hope it helps,

						Olivier L'Heureux

----------------------------------------------------------------------

Laboratoire de microélectronique de l'Université catholique de Louvain

e-mail:	lheureux@dice.ucl.ac.be	               B-1348 Louvain-la-Neuve
<URL:http://www.dice.ucl.ac.be/~lheureux>                      Belgium
MIME/PGP accepted

--Multipart Mon Feb 12 12:54:19 1996
Content-Type: text/plain; charset=US-ASCII

Hello,

I succeeded in building LEDA-3.2.3 as a shared library. It seems to be
a useful information for many people, so I explain here how I did it.

Foreword:

  I compiled "LEDA-R-3.2.3" on a Sun SPARCstation 20.
  The operation system was Solaris 2.4 (SunOS 5.4) with patch 101945-13.
  The compiler used was gcc version 2.7.0.

  The modifications proposed here are given without any guarantee.
  The entire risk as to the quality, performances or consequences of
  the modifications is with you.

I may not guarantee it will work on other systems, though I believe it
will on any Solaris2.x with at least gcc-2.6.3. `CC' should probably
work too, with the same philosophy. Perhaps it works on Linux too,
using the C++ sources in the `number' directory.

Without the shared libraries, compiling all the programmes with
`-g -O' requires more than 100 MB ! With the shared libraries, `ged'
takes 32 KB and `voronoi' 60 KB, for instance. When benchmarking the
resulting executables, dynamically linked ones seems to be slower by
approximately 10 %.

I would be interested if someone try to build the shared libraries and
describes its problems.

Philosophy:

  1) Produce only PIC (Position-Independent Code) objects.
  2) Build the normal libraries (`libL.a', `libG.a', `libP.a' and
     `libWx.a')
  3) Extract the object files from the libraries, and build a shared
     object with them. Call it `lib{L,G,P,Wx}.so.3.2.3'. Place it in the
     same directory as the original `lib{L,G,P,Wx}.a'.
  4) Put a symbolic link from `lib{L,G,P,Wx}.so' to the
     corresponding `lib{L,G,P,Wx}.so.3.2.3'

Now you may compile normally, and the executables will be dynamically
linked. If you want statically linked libraries, use the option
`-static' in g++.

A alpha-release patch for the files to be modified is given in appendix.

Details:

1.1) Compile everything with the option `-fpic'. One way to do it is
     to change the top Makefile, use

	cd src;  $(MAKE) -i FLAGS="\"-g -fpic -O\""

     in place of

	cd src;  $(MAKE) -i FLAGS=-g

     for instance. The `-g' and `-O' options are up to you.

1.2) One special problem arise with the SPARC assembly sources in
     "src/numbers". You need also to assemble with the `-K PIC'
     option, so change :

	.s.o:
		as -o $*.o $*.s

     in 

	.s.o:
		as -K PIC -o $*.o $*.s

     in "src/Make.src".

     The files `_sparc_mul.s' and `_sparc_div.s', assembled with
     `-K PIC', do not cause further problems. But `_sparc_add.s' and
     `_sparc_sub.s' do, they seem to have been compiled with gcc but
     without `-fpic'. So recompile them from `_sgnu_add.c' and
     `_sgnu_sub.c'. But there is a declaration problem: the
     `School_Add' function is declared 
     
	#define School_Add      _School_Add
	extern "C" sz_t School_Add(word*,sz_t,word*,sz_t,word*);

     in "src/numbers/_integer.c" and

	extern sz_t School_Add(word *a, sz_t a_used, word *b, sz_t b_used, word* sum)

     in "src/numbers/_sgnu_add.c". Compiling it so will not link,
     because `_School_Add' will not be found. Modify thus
     the declaration in `_sgnu_add.c' and put:

	sz_t _School_Add(word *a, sz_t a_used, word *b, sz_t b_used, word* sum)

     in place of the `extern' definition. Similarly, replace:

	extern sz_t School_Sub(word *a, sz_t a_used, word *b, sz_t b_used, word* diff)
     by

	sz_t _School_Sub(word *a, sz_t a_used, word *b, sz_t b_used, word* diff)

     in "src/numbers/_sgnu_sub.c".
     Compile them with `-fpic'. You may add the following lines in
     "src/numbers/Makefile":

	_sparc_add.o: _sgnu_add.c
	      gcc -O -fpic -o $@ -c $<

	_sparc_sub.o: _sgnu_sub.c
	      gcc -O -fpic -o $@ -c $<

     I don't know what are the consequences of these modification on
     the efficiency of the resulting code, but I believe they are
     small (10-20 % ?).
   
3.1) One easy way to build a `lib?.so.3.2.3' library from a `lib?.a'
     is to create a directory, extract all the `.o' files there, and
     reassemble the result. For instance:

	mkdir shared_L
	cd shared_L
	ar xv ../libL.a
	cd ..
	g++ -shared -o /dir/leda/LEDA-3.2.3/libL.so.3.2.3 shared_L/*.o
	rm -r shared_L

     This may be automated in the top Makefile:

	# Shared libraries on Solaris 2.4 with gcc.

	# Absolute path for the libraries, change with your own.
	LEDADIR=/dir/leda/LEDA-3.2.3

	lib%.so.3.2.3: lib%.a
		mkdir sh_$<
		(cd sh_$<; ar xv ../$<)
		g++ -shared -o $(LEDADIR)/$@ sh_$</*.o
		rm -r sh_$<

	lib%.so: lib%.so.3.2.3
		ln -s $< $@

	shared_lib: libL.so libL.so.3.2.3
	shared_lib: libG.so libG.so.3.2.3
	shared_lib: libP.so libP.so.3.2.3 
	shared_lib: libWx.so libWx.so.3.2.3

     Enter then `make shared_lib'.

     It is important to give an absolute path for the library created,
     because this path will be used for dynamic linking. The path
     should refer to the right shared library at _compile_ time *and*
     at _execution_ time.

     There are actually two ways for Solaris to find the dynamic
     objects: either they are specified by an absolute path, or they
     are searched through the $LD_LIBRARY_PATH environment
     variable. We used the first, you may choose the second. Then,
     specify only a basename, like:

	g++ -shared -o libL.so.3.2.3 shared_L/*.o

     You must then explain at execution time where to find LEDA's
     dynamic libraries:

	setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/dir/leda/LEDA-3.2.3

     before you start the executables. This gives you an idea of the
     result:

	sphinx34> ls -l ged voronoi
	-rwxr-xr-x  1 lheureux    32840 Oct 31 15:38 ged
	-rwxr-xr-x  1 lheureux    59640 Oct 31 15:38 voronoi
	sphinx35> file ged voronoi
	ged:            ELF 32-bit MSB executable SPARC Version 1, dynamically linked, stripped
	voronoi:        ELF 32-bit MSB executable SPARC Version 1, dynamically linked, stripped
	sphinx36> ldd ged
		/dir/leda/LEDA-3.2.3/libP.so.3.2.3
		/dir/leda/LEDA-3.2.3/libG.so.3.2.3
		/dir/leda/LEDA-3.2.3/libL.so.3.2.3
		/dir/leda/LEDA-3.2.3/libWx.so.3.2.3
		libX11.so.5.0 =>         /usr/X11R5/lib/libX11.so.5.0
		libsocket.so.1 =>        /usr/lib/libsocket.so.1
		libstdc++.so.2.7.0 =>    /usr/lib/libstdc++.so.2.7.0
		libm.so.1 =>     /usr/lib/libm.so.1
		libc.so.1 =>     /usr/lib/libc.so.1
		libnsl.so.1 =>   /usr/lib/libnsl.so.1
		libdl.so.1 =>    /usr/lib/libdl.so.1
		libintl.so.1 =>  /usr/lib/libintl.so.1
		libw.so.1 =>     /usr/lib/libw.so.1
	sphinx37> 

You may try to compile the programmes in the `prog' directory, but you
have then to modify the Makefiles. Indeed, the programmes in
`prog/basic', for instance, are linked with $UNIXLIB, defined in
`prog/basic/Makefile' as

	UNIXLIB = ../../libL.a -lm

They must be linked with

	UNIXLIB = -L../.. -lL -lm

in order to find the dynamic library `libL.so'. Whenever you use
`-lP', you _must_ use `-lX11 -lsocket', because _all_ the references
in `libP.so.3.2.3' must be resolved, even if you do not really use
X11.
--Multipart Mon Feb 12 12:54:19 1996
Content-Type: text/plain; charset=US-ASCII


*** ./src/numbers/Makefile	Tue Oct 24 12:31:06 1995
--- ./src/numbers/Makefile.orig	Fri Sep 15 15:42:49 1995
***************
*** 9,19 ****
  	$(RANLIB)
  	touch sparc
  
! _sparc_add.o: _sgnu_add.c
! 	gcc -O -fpic -o $@ -c $<
! 
! _sparc_sub.o: _sgnu_sub.c
! 	gcc -O -fpic -o $@ -c $<
   
  sparc-clean:
  	rm -f _sparc*.o
--- 9,17 ----
  	$(RANLIB)
  	touch sparc
  
! sparc_gnu:
! 	gcc -O -S _sgnu_add.c
! 	gcc -O -S _sgnu_sub.c
   
  sparc-clean:
  	rm -f _sparc*.o
*** ./src/numbers/_sgnu_add.c	Tue Oct 24 15:48:58 1995
--- ./src/numbers/_sgnu_add.c.orig	Fri Sep 15 15:54:53 1995
***************
*** 15,21 ****
  typedef unsigned long  word;
  typedef unsigned int sz_t;
  
! sz_t _School_Add(word *a, sz_t a_used, word *b, sz_t b_used, word* sum)
  {
    /* compute sum = a + b   (a_used >= b_used) */
  
--- 15,21 ----
  typedef unsigned long  word;
  typedef unsigned int sz_t;
  
! extern sz_t School_Add(word *a, sz_t a_used, word *b, sz_t b_used, word* sum)
  {
    /* compute sum = a + b   (a_used >= b_used) */
  
*** ./src/numbers/_sgnu_sub.c	Tue Oct 24 15:49:24 1995
--- ./src/numbers/_sgnu_sub.c.orig	Fri Sep 15 15:54:54 1995
***************
*** 16,22 ****
  typedef unsigned long  word;
  typedef unsigned int sz_t;
  
! sz_t _School_Sub(word *a, sz_t a_used, word *b, sz_t b_used, word* diff)
  {
    /* compute diff = a - b    (a > b) */
  
--- 16,24 ----
  typedef unsigned long  word;
  typedef unsigned int sz_t;
  
! 
! 
! extern sz_t School_Sub(word *a, sz_t a_used, word *b, sz_t b_used, word* diff)
  {
    /* compute diff = a - b    (a > b) */
  
*** ./src/Make.src	Tue Oct 24 09:40:29 1995
--- ./src/Make.src.orig	Fri Sep 15 15:42:47 1995
***************
*** 4,17 ****
  LIB    = ../../$(L).a
  CFLAGS = -O
  ARLIB  = ar r $(LIB) $?
! # RANLIB = ranlib $(LIB)
! RANLIB = true
  o      = .o
  .c.o:
  	../../c++  -I../../incl $(CFLAGS) $(DFLAGS) -c $*.c
  
  .s.o:
! 	as -K PIC -o $*.o $*.s
  
  
  #-----------------------------------------------------------------------------
--- 4,16 ----
  LIB    = ../../$(L).a
  CFLAGS = -O
  ARLIB  = ar r $(LIB) $?
! RANLIB = ranlib $(LIB)
  o      = .o
  .c.o:
  	../../c++  -I../../incl $(CFLAGS) $(DFLAGS) -c $*.c
  
  .s.o:
! 	as -o $*.o $*.s
  
  
  #-----------------------------------------------------------------------------
*** ./prog/plane/Makefile	Tue Oct 24 16:34:24 1995
--- ./prog/plane/Makefile.orig	Fri Sep 15 15:42:57 1995
***************
*** 1,5 ****
  
! UNIXLIB = -L../.. -lP -lG -lL -lWx -lX11 -lsocket -lm
  
  DOSLIB = ..\\..\\libp.lib ..\\..\\libg.lib ..\\..\\libl.lib
  
--- 1,5 ----
  
! UNIXLIB = ../../libP.a ../../libG.a ../../libL.a -lm
  
  DOSLIB = ..\\..\\libp.lib ..\\..\\libg.lib ..\\..\\libl.lib
  
*** ./prog/graph/Makefile	Tue Oct 24 11:56:58 1995
--- ./prog/graph/Makefile.orig	Fri Sep 15 15:42:59 1995
***************
*** 1,5 ****
  
! UNIXLIB = -L../.. -lG -lL -lm
  
  DOSLIB = ..\\..\\libg.lib ..\\..\\libl.lib
  
--- 1,5 ----
  
! UNIXLIB = ../../libG.a ../../libL.a -lm
  
  DOSLIB = ..\\..\\libg.lib ..\\..\\libl.lib
  
*** ./prog/basic/Makefile	Tue Oct 24 11:54:08 1995
--- ./prog/basic/Makefile.orig	Fri Sep 15 15:43:02 1995
***************
*** 1,5 ****
  
! UNIXLIB = -L../.. -lL -lm
  
  DOSLIB = ..\\..\\libl.lib
  
--- 1,5 ----
  
! UNIXLIB = ../../libL.a -lm
  
  DOSLIB = ..\\..\\libl.lib
  
*** ./prog/sweep/makefile	Tue Oct 24 12:05:51 1995
--- ./prog/sweep/makefile.orig	Fri Sep 15 15:43:04 1995
***************
*** 3,10 ****
  
  CFLAGS = -O
  
! LIBS = -L../.. -lP -lG -lL -lm
! LIBX = -L../.. -lP -lG -lL ../../libWx.a -lX11 -lm
  
  .c.o:
  	$(CC) $(CFLAGS) -c $*.c
--- 3,10 ----
  
  CFLAGS = -O
  
! LIBS = ../../libP.a ../../libG.a ../../libL.a -lm
! LIBX = ../../libP.a ../../libG.a ../../libL.a ../../libWx.a -lX11 -lm
  
  .c.o:
  	$(CC) $(CFLAGS) -c $*.c
*** ./prog/prio/Makefile	Tue Oct 24 11:55:05 1995
--- ./prog/prio/Makefile.orig	Fri Sep 15 15:43:06 1995
***************
*** 1,5 ****
  
! UNIXLIB = -L../.. -lL -lm
  
  DOSLIB = ..\\..\\libl.lib
  
--- 1,5 ----
  
! UNIXLIB = ../../libL.a -lm
  
  DOSLIB = ..\\..\\libl.lib
  
*** ./prog/dict/Makefile	Tue Oct 24 11:56:12 1995
--- ./prog/dict/Makefile.orig	Fri Sep 15 15:43:06 1995
***************
*** 1,5 ****
  
! UNIXLIB = -L../.. -lL -lm
  
  DOSLIB = ..\\..\\libl.lib
  
--- 1,5 ----
  
! UNIXLIB = ../../libL.a -lm
  
  DOSLIB = ..\\..\\libl.lib
  
*** ./prog/demo/Makefile	Tue Oct 24 12:04:19 1995
--- ./prog/demo/Makefile.orig	Fri Sep 15 15:43:10 1995
***************
*** 1,5 ****
   
! UNIXLIB = -L../.. -lP -lG -lL -lWx -lX11 -lm -lsocket
  
  DOSLIB = ..\\..\\libp.lib ..\\..\\libg.lib ..\\..\\libl.lib ..\\..\\libwx.lib
  
--- 1,5 ----
   
! UNIXLIB = ../../libP.a ../../libG.a ../../libL.a ../../libWx.a -lX11 -lm
  
  DOSLIB = ..\\..\\libp.lib ..\\..\\libg.lib ..\\..\\libl.lib ..\\..\\libwx.lib
  
*** ./prog/window/Makefile	Tue Oct 24 17:19:31 1995
--- ./prog/window/Makefile.orig	Fri Sep 15 15:43:13 1995
***************
*** 1,5 ****
   
! UNIXLIB = -L../.. -lP -lG -lL -lWx -lX11 -lsocket -lm
  
  DOSLIB = ..\\..\\libp.lib ..\\..\\libg.lib ..\\..\\libl.lib ..\\..\\libwx.lib
  
--- 1,5 ----
   
! UNIXLIB = ../../libP.a ../../libG.a ../../libL.a ../../libWx.a -lX11 -lm
  
  DOSLIB = ..\\..\\libp.lib ..\\..\\libg.lib ..\\..\\libl.lib ..\\..\\libwx.lib
  
*** ./man/extman.awk	Mon Oct 16 16:37:19 1995
--- ./man/extman.awk.orig	Fri Sep 15 15:43:17 1995
***************
*** 1,5 ****
! # BEGIN { datatype = "?????????????"; }
! BEGIN { datatype = "............."; }
  
  function removeweb() 
  { x = 0; 
--- 1,4 ----
! BEGIN { datatype = "?????????????"; }
  
  function removeweb() 
  { x = 0; 
***************
*** 57,64 ****
  /\/\*{\\Mbinopfunc/ {
    split(memberfunc,arr);
    if (arr[2] !~ /[a-z,A-Z]+.*/)   # binary operator
!   {
!     sub(/arr[2]/,"",memberfunc);
      sub(/\(/,"",memberfunc);
      sub(/\)/,"",memberfunc);
      sub(/\,/,"\\ "arr[2],memberfunc);
--- 56,62 ----
  /\/\*{\\Mbinopfunc/ {
    split(memberfunc,arr);
    if (arr[2] !~ /[a-z,A-Z]+.*/)   # binary operator
!   { sub(arr[2],"",memberfunc);
      sub(/\(/,"",memberfunc);
      sub(/\)/,"",memberfunc);
      sub(/\,/,"\\ "arr[2],memberfunc);
*** ./man/tman	Mon Oct 16 17:42:02 1995
--- ./man/tman.orig	Fri Sep 15 15:43:14 1995
***************
*** 1,7 ****
  #!/bin/csh -f
  
  # set LEDA_HOME = your LEDA home directory
! set LEDA_HOME = /dir/leda/LEDA-3.2.3
  
  # LEDA include directory
  set INCL = $LEDA_HOME/incl/LEDA
--- 1,7 ----
  #!/bin/csh -f
  
  # set LEDA_HOME = your LEDA home directory
! set LEDA_HOME = /LEDA/SRC
  
  # LEDA include directory
  set INCL = $LEDA_HOME/incl/LEDA
***************
*** 56,63 ****
  echo ""					>> $tmpfile.tex
  echo "\begin{document}"                 >> $tmpfile.tex
  echo "\chapter{ }"			>> $tmpfile.tex
! # gawk -f $MAN/extman.awk $INCL/$1.h      >> $tmpfile.tex
! $MAN/Awk -f $MAN/extman.awk $INCL/$1.h      >> $tmpfile.tex
  echo "\end{document}"			>> $tmpfile.tex
  
  
--- 56,62 ----
  echo ""					>> $tmpfile.tex
  echo "\begin{document}"                 >> $tmpfile.tex
  echo "\chapter{ }"			>> $tmpfile.tex
! gawk -f $MAN/extman.awk $INCL/$1.h      >> $tmpfile.tex
  echo "\end{document}"			>> $tmpfile.tex
  
  
*** ./man/Makefile	Mon Oct 16 16:36:32 1995
--- ./man/Makefile.orig	Fri Sep 15 15:43:15 1995
***************
*** 1,4 ****
- SHELL= /bin/csh
  
  MANUAL.ps: MANUAL.dvi
  	dvips MANUAL.dvi
--- 1,3 ----
*** ./Makefile	Tue Oct 31 16:43:16 1995
--- ./Makefile.orig	Fri Sep 15 15:42:14 1995
***************
*** 11,43 ****
  lib_g: 
  	cd src;  $(MAKE) -i FLAGS=-g
  
- lib_gO: 
- 	cd src;  $(MAKE) -i FLAGS="\"-g -fpic -O\""
- 
  lib_pg: 
  	cd src;  $(MAKE) -i FLAGS=-pg
  
  lib_w: 
  	cd src;  $(MAKE) -i FLAGS=-Wall
  
- # Shared libraries on Solaris 2.4 with gcc.
- 
- # Absolute path for the libraries, change with your own.
- LEDADIR=/dir/leda/LEDA-3.2.3
  
- lib%.so.3.2.3: lib%.a
- 	mkdir sh_$<
- 	(cd sh_$<; ar xv ../$<)
- 	g++ -shared -o $(LEDADIR)/$@ sh_$</*.o
- 	rm -r sh_$<
- 
- lib%.so: lib%.so.3.2.3
- 	ln -s $< $@
- 
- shared_lib: libL.so libL.so.3.2.3
- shared_lib: libG.so libG.so.3.2.3
- shared_lib: libP.so libP.so.3.2.3 
- shared_lib: libWx.so libWx.so.3.2.3
  
  #------------------------------------------------------------------------------
  # Programs
--- 11,23 ----
***************
*** 51,59 ****
  
  pro_g:
  	cd prog; $(MAKE) -i FLAGS=-g
- 
- pro_gO:
- 	cd prog; $(MAKE) -i FLAGS="\"-g -O\""
  
  pro_pg:
  	cd prog; $(MAKE) -i FLAGS=-pg
--- 31,36 ----
--Multipart Mon Feb 12 12:54:19 1996--
Technical Details
Message-ID: <LHEUREUX.96Feb12125523@sphinx.dice.ucl.ac.be>
Path: arc1-ca.pugleaf.net!news.sri.ucl.ac.be!lheureux
References: <ROADHOZF.96Feb2141851@sun16.engin.brown.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.sri.ucl.ac.be!lheureux
From: Olivier L'Heureux <lheureux@dice.ucl.ac.be>
Newsgroups: comp.lang.c++.leda
Subject: Re: Shared Library under Solaris
Date: 12 Feb 1996 11:55:23 GMT
Organization: Lab. de Microelectronique - UCL - Belgium
Distribution: world
Message-ID: <LHEUREUX.96Feb12125523@sphinx.dice.ucl.ac.be>
References: <ROADHOZF.96Feb2141851@sun16.engin.brown.edu>
NNTP-Posting-Host: ns3.dice.ucl.ac.be
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="Multipart Mon Feb 12 12:54:19 1996"
Content-Transfer-Encoding: 7bit
In-reply-to: roadhozf@sun16.engin.brown.edu's message of 02 Feb 1996
 19:18:47 GMT