shu@kivax.UUCP (Schultis Abt.013.2) (08/29/88)
I've tried to build a shared library and found a serious problem and now I need some help. Has anyone created their own shared library containing lots of references to system type C-functions, e.g. how can FILE *popen() be linked to the target file so that all references are covered? ---------------------------------------------------------------- Gerhard Schultis shu@kivax.uucp Mannesmann Kienzle GmbH 7730 VS-Villingen -Germany
torsten@pcsbst.UUCP (Torsten Homeyer) (08/31/88)
In article <462@kivax.UUCP> shu@kivax.UUCP (Schultis Abt.013.2) writes: > >I've tried to build a shared library and found a serious problem >and now I need some help. >Has anyone created their own shared library containing lots of >references to system type C-functions, >e.g. how can FILE *popen() be linked to the target file so that >all references are covered? > Hope i can help you a bit. Look past my signature. mfg Torsten. --- Name : Torsten Homeyer {tho@pcsbst ; torsten@homeyer}.UUCP Company : PCS GmbH, Munich W-Germany. UUCP : ..uunet!unido!pcsbst!tho ..uunet!unido!pcsbst!sws4!torsten PRIVAT: ..unido!{pcsbst,megalon,mikros,[altger,netmbx]!oldman}!homeyer!torsten ------------------------------------------------------------------------------ #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of shell archive." # Contents: SH SH/README SH/import.h SH/libmaux.s1 SH/log.c SH/main.c # SH/makefile SH/maux.h SH/maux_defs.c SH/poly.c SH/stats.c # Wrapped by torsten@sws4 on Wed Aug 31 16:06:37 1988 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test ! -d 'SH' ; then echo shar: Creating directory \"'SH'\" mkdir 'SH' fi if test -f 'SH/README' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'SH/README'\" else echo shar: Extracting \"'SH/README'\" \(844 characters\) sed "s/^X//" >'SH/README' <<'END_OF_FILE' from: tho@pcsbst.uucp, ...uunet!unido!pcsbst!tho; Torsten Homeyer X at PCS GmbH, Munich , West-Germany X X Hints in the shared library description from ATT. This corresponds to the description "Building a shared library" in the Programmers guide. X X1. In the Specifications File you have to prepend an underscore to the X symbols referenced in the following sections : X #branch X #export linker X #init xx.o X X X2. Be shure to have "max number of segments per user" set to the X right value when generating the kernel. Normal it is set to 3 (.text, X .data, .bss) + SHMSEG /* max number of shared segment per user */ from X the shared memory tunable parameters + 1. That together normaly is 7. X You must add 3 foreach shared library you want to use simultaneously in X one program. X For PCS-machines you tune it in /usr/sys/conf.h; X #define SHMSEG xx X END_OF_FILE if test 844 -ne `wc -c <'SH/README'`; then echo shar: \"'SH/README'\" unpacked with wrong size! fi # end of 'SH/README' fi if test -f 'SH/import.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'SH/import.h'\" else echo shar: Extracting \"'SH/import.h'\" \(128 characters\) sed "s/^X//" >'SH/import.h' <<'END_OF_FILE' X#ifdef SHARED X#define malloc (*_libmaux_malloc) X#define log (*_libmaux_log) X#endif X extern char *malloc(); extern double log(); END_OF_FILE if test 128 -ne `wc -c <'SH/import.h'`; then echo shar: \"'SH/import.h'\" unpacked with wrong size! fi # end of 'SH/import.h' fi if test -f 'SH/libmaux.s1' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'SH/libmaux.s1'\" else echo shar: Extracting \"'SH/libmaux.s1'\" \(318 characters\) sed "s/^X//" >'SH/libmaux.s1' <<'END_OF_FILE' X## X## X#address .text 0x3de00000 X#address .data 0x3df00000 X#target /usr/service/torsten/C/SH/libmaux_s X#branch X _polyd 1 X _logd 2 X _maux_stat 3 X#objects X maux_defs.o X poly.o X log.o X stats.o X#objects noload X -lc_s X#hide linker * X#export linker X _mauxerr X#init maux_defs.o X __libmaux_malloc _malloc X __libmaux_log _log END_OF_FILE if test 318 -ne `wc -c <'SH/libmaux.s1'`; then echo shar: \"'SH/libmaux.s1'\" unpacked with wrong size! fi # end of 'SH/libmaux.s1' fi if test -f 'SH/log.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'SH/log.c'\" else echo shar: Extracting \"'SH/log.c'\" \(400 characters\) sed "s/^X//" >'SH/log.c' <<'END_OF_FILE' X#include"maux.h" X#include"import.h" X#include<math.h> X double logd(base,x) X double base, x; X{ X extern int stats_logd; X extern int total_calls; X X double logbase; X double logx; X X total_calls++; X stats_logd++; X logbase = log((double)base); X logx = log((double)x); X if(logbase == -HUGE || logx == -HUGE) X { X mauxerr = 1; X return(0); X } X else X mauxerr= 0; X return(logx/logbase); X} static int mauxdummy; END_OF_FILE if test 400 -ne `wc -c <'SH/log.c'`; then echo shar: \"'SH/log.c'\" unpacked with wrong size! fi # end of 'SH/log.c' fi if test -f 'SH/main.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'SH/main.c'\" else echo shar: Extracting \"'SH/main.c'\" \(135 characters\) sed "s/^X//" >'SH/main.c' <<'END_OF_FILE' X#include<stdio.h> X extern double logd(); X main() X{ X double erg; X X erg = logd(2.0,10.343); X printf("logd(2.0, 10.343) == %f\n", erg); X} END_OF_FILE if test 135 -ne `wc -c <'SH/main.c'`; then echo shar: \"'SH/main.c'\" unpacked with wrong size! fi # end of 'SH/main.c' fi if test -f 'SH/makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'SH/makefile'\" else echo shar: Extracting \"'SH/makefile'\" \(872 characters\) sed "s/^X//" >'SH/makefile' <<'END_OF_FILE' X shlib: log.c main.c maux_defs.c poly.c stats.c X cc -c -fT -DSHARED maux_defs.c poly.c log.c stats.c X mkshlib -s libmaux.s1 -t libmaux_s -h libmaux_s.a X rm *.o X X lib: log.c main.c maux_defs.c poly.c stats.c X cc -c -fT maux_defs.c poly.c log.c stats.c X ar rv maux maux_defs.o poly.o log.o stats.o X rm *.o X main: main.c maux X cc -d -fT -o main main.c maux X X X X smain: main.c libmaux_s.a X cc -fT -o smain main.c libmaux_s.a X X# we can't do the following in this example because needing a printf which X#understands float from libm.a X# cc -fT -o shmain main.c libmaux_s.a -lc_s X#expands to X# ld -o shmain /lib/crt0.o main.o libmaux_s.a -lc_s -lm -lc X#so we don't get the right printf. X#But we can call the linker by hand, and it will work. X# Look at the following example: X X shmain: main.c libmaux_s.a X cc -fT -c main.c X ld -o shmain /lib/crt0.o main.o libmaux_s.a -lm -lc_s -lc END_OF_FILE if test 872 -ne `wc -c <'SH/makefile'`; then echo shar: \"'SH/makefile'\" unpacked with wrong size! fi # end of 'SH/makefile' fi if test -f 'SH/maux.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'SH/maux.h'\" else echo shar: Extracting \"'SH/maux.h'\" \(174 characters\) sed "s/^X//" >'SH/maux.h' <<'END_OF_FILE' X struct mstats X { X int st_polyd; X int st_logd; X int st_total; X }; X X X X extern double polyd(); extern double logd(); extern struct mstats *maux_stat(); X extern int mauxerr; END_OF_FILE if test 174 -ne `wc -c <'SH/maux.h'`; then echo shar: \"'SH/maux.h'\" unpacked with wrong size! fi # end of 'SH/maux.h' fi if test -f 'SH/maux_defs.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'SH/maux_defs.c'\" else echo shar: Extracting \"'SH/maux_defs.c'\" \(103 characters\) sed "s/^X//" >'SH/maux_defs.c' <<'END_OF_FILE' X int mauxerr = 0; X X X#ifdef SHARED double (*_libmaux_log)() = 0; char *(*_libmaux_malloc)() = 0; X#endif END_OF_FILE if test 103 -ne `wc -c <'SH/maux_defs.c'`; then echo shar: \"'SH/maux_defs.c'\" unpacked with wrong size! fi # end of 'SH/maux_defs.c' fi if test -f 'SH/poly.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'SH/poly.c'\" else echo shar: Extracting \"'SH/poly.c'\" \(390 characters\) sed "s/^X//" >'SH/poly.c' <<'END_OF_FILE' X#include"maux.h" X#include"import.h" X#include<math.h> X double polyd(a, n, x) X double a[]; X int n; X double x; X{ X extern int stats_polyd; X extern int total_calls; X double result; X int i; X X total_calls++; X stats_polyd++; X if(n < 0) X { X mauxerr = 1; X return(0); X } X result = a[0]; X for(i = 1; i <= n; i++) X { X result *= (double)x; X result += (double)a[i]; X } X mauxerr= 0; X return(result); X} END_OF_FILE if test 390 -ne `wc -c <'SH/poly.c'`; then echo shar: \"'SH/poly.c'\" unpacked with wrong size! fi # end of 'SH/poly.c' fi if test -f 'SH/stats.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'SH/stats.c'\" else echo shar: Extracting \"'SH/stats.c'\" \(351 characters\) sed "s/^X//" >'SH/stats.c' <<'END_OF_FILE' X#include"maux.h" X#include"import.h" X int total_calls = 0; int stats_logd = 0; int stats_polyd = 0; X struct mstats *maux_stat() X{ X extern char *malloc(); X struct mstats *st; X X if((st = (struct mstats *)malloc(sizeof(struct mstats))) == 0) X return(0); X st->st_polyd = stats_polyd; X st->st_logd = stats_logd; X st->st_total = total_calls; X return(st); X} END_OF_FILE if test 351 -ne `wc -c <'SH/stats.c'`; then echo shar: \"'SH/stats.c'\" unpacked with wrong size! fi # end of 'SH/stats.c' fi echo shar: End of shell archive. exit 0