hi,
we are having problems with the order of libraries for compiling. we
have cut it down to a short example. we create a shared library called
libs4utl.so;
if we cc with "-ls4utl -lposix4" the program dumps core;
if we cc with "-lposix4 -ls4utl" the program runs correctly.
my understanding is that our library should come before the system
libraries. the program dumps core in a constructor on a sem_init.
this is using Sun WorkShop 5.0 on Solaris 7 (on an E450). it works fine
using "-ls4utl -lposix4" with WS 5.0 on Solaris 2.6 (on an E2), and with
WS 4.2 on Solaris 2.6 (on an E450). i am including the small example,
total is 114 lines.
any thoughts?
marc
(dejanews seems to be having fun with the line formatting...)
included files :
Doit
Doit.ok
dumlib.c
dumpgm.c
makefile
makefile.ok
------------------------- Doit -------------------------
#!/bin/ksh
make clean
make
export LD_LIBRARY_PATH=.
echo ================================ Running dumpgm
./dumpgm
------------------------- end of Doit -------------------------
------------------------- Doit.ok -------------------------
#!/bin/ksh
make -f makefile.ok clean
make -f makefile.ok
export LD_LIBRARY_PATH=.
echo ================================ Running dumpgm
./dumpgm
------------------------- end of Doit.ok -------------------------
------------------------- dumlib.c -------------------------
#include <stdio.h>
#include <semaphore.h>
#pragma init (dumlib_constructor)
#pragma fini (dumlib_destructor)
static void dumlib_constructor (void);
static void dumlib_destructor (void);
static sem_t gsem;
static void dumlib_constructor(void)
{
fprintf (stderr, "in constructor\n");
sem_init(&gsem,0,0);
static void dumlib_destructor(void)Quote:}
{
fprintf (stderr, "in destructor\n");
sem_destroy(&gsem);
int dumlib_func(void)Quote:}
{
sem_post(&gsem);
return(1);
------------------------- end of dumlib.c -------------------------Quote:}
------------------------- dumpgm.c -------------------------
#include <stdio.h>
#include <semaphore.h>
int dumlib_func(void);
int main(int argc,char *argv[])
{
fprintf(stderr,"call dumlib_func rc=%d\n",dumlib_func());
return(0);
------------------------- end of dumpgm.c -------------------------Quote:}
------------------------- makefile -------------------------
CC=/opt/SUNWspro/bin/cc
CFLAGS= -g -xCC -v -mt -Kpic -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS
-D_POSIX_C_SOURCE=199506L
LBFLAGS=-G
LDLIBS=-lposix4
LDDIRS=-L. -L/usr/local/lib
SHELL=/bin/sh
LIBUTL=s4utl
UTLLIB=lib$(LIBUTL).so
UTLSRC=dumlib.c
UTLOBJS=$(UTLSRC:.c=.o)
default: all
dumlib.o: dumlib.c
all: dumpgm $(UTLLIB)
$(UTLLIB): $(UTLOBJS)
$(CC) $(CFLAGS) $(LBFLAGS) $(UTLOBJS) -o $(UTLLIB)
dumpgm: dumpgm.c $(UTLLIB)
$(CC) $(CFLAGS) dumpgm.c $(LDDIRS) -l$(LIBUTL) $(LDLIBS) -o
dumpgm
clean:
rm -f *.o dumpgm $(UTLLIB) core
.SUFFIXES: .o .c
------------------------- end of makefile -------------------------
------------------------- makefile.ok -------------------------
CC=/opt/SUNWspro/bin/cc
CFLAGS= -g -xCC -v -mt -Kpic -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS
-D_POSIX_C_SOURCE=199506L
LBFLAGS=-G
LDLIBS=-lposix4
LDDIRS=-L. -L/usr/local/lib
SHELL=/bin/sh
LIBUTL=s4utl
UTLLIB=lib$(LIBUTL).so
UTLSRC=dumlib.c
UTLOBJS=$(UTLSRC:.c=.o)
default: all
dumlib.o: dumlib.c
all: dumpgm $(UTLLIB)
$(UTLLIB): $(UTLOBJS)
$(CC) $(CFLAGS) $(LBFLAGS) $(UTLOBJS) -o $(UTLLIB)
dumpgm: dumpgm.c $(UTLLIB)
$(CC) $(CFLAGS) dumpgm.c $(LDDIRS) $(LDLIBS) -l$(LIBUTL) -o
dumpgm
clean:
rm -f *.o dumpgm $(UTLLIB) core
.SUFFIXES: .o .c
------------------------- end of makefile.ok -------------------------
Sent via Deja.com http://www.deja.com/
Before you buy.