library order problem with WorkShop 5.0 & Solaris 7

library order problem with WorkShop 5.0 & Solaris 7

Post by marc_desroch.. » Tue, 21 Mar 2000 04:00:00



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);
Quote:}

static void dumlib_destructor(void)
{
fprintf (stderr, "in destructor\n");
sem_destroy(&gsem);
Quote:}

int dumlib_func(void)
{
sem_post(&gsem);
return(1);
Quote:}

------------------------- end of dumlib.c -------------------------
------------------------- 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);
Quote:}

------------------------- end of dumpgm.c -------------------------
------------------------- 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.

 
 
 

library order problem with WorkShop 5.0 & Solaris 7

Post by Rod Evan » Tue, 21 Mar 2000 04:00:00



> if we cc with "-ls4utl -lposix4" the program dumps core;
> if we cc with "-lposix4 -ls4utl" the program runs correctly.

Your libraries .init is firing before librt:

 % ldd -i dumpgm
  .....
   init library=/usr/lib/libthread.so.1
   init library=./libs4utl.so
   init library=/usr/lib/libc.so.1
   init library=/usr/lib/libaio.so.1
   init library=/usr/lib/librt.so.1

make sure your libraries are built with their required dependencies:

 % cc -g -xCC  ..... -G dumlib.o -o libs4utl.so  -zdefs -lposix4 -lc

then their .inits will fire correctly:

 % ldd -i dumpgm
  .....
   init library=/usr/lib/libthread.so.1
   init library=/usr/lib/libc.so.1
   init library=/usr/lib/libaio.so.1
   init library=/usr/lib/librt.so.1
   init library=./libs4utl.so

 % ================================ Running dumpgm
 in constructor
 call dumlib_func rc=1
 in destructor

--

Rod.

 
 
 

1. Compilation Problem: solaris 5.7 and Sun Workshop 5.0

We are compiling a piece of code on Solaris 2.7 with Sun Workshop 5.0.
While linking if we give cout in the code it gives the following error
:

undefined symbol
std::basic_ostream<char,std::char_traits<char>

But if we declare a boolean variable and output it usnig cout before
any other cout call in the code it works fine .
i.e if I add

bool bTemp = true;
cout<<bTemp<<endl;

before the first call to cout then it works fine. We are calling some
third party libraries from this piece of code.
One similar problem comes when I use "ofstream" type of object in
other shared library, It compiles fine but fails when called from an
executable.
This whole thing is working fine on Solaris 2.8. I feel the problem is
due to some incompatible libraries.

Can anybody suggest any patch recommended, or solution to this
problem.

Regards
Deepesh

2. IP Multicast / Broadcast

3. Need help to run SUN Workshop 5.0 beta (problems to run solaris license manager)

4. What happens to the stdio channels in a ¢? ·RPC-Service started by remsh ?

5. Problems compiling glib (solaris 5.6, Sun Workshop C++ 5.0)

6. Virtual Linux Machine

7. Solaris 2.5.1 Workshop 5.0 Debug Problem

8. Canon BJC 4100 color

9. Using the OTL oracle library with Sun Workshop 5.0

10. TclTk 8.0 & C++ (g++) shared library w/stream I/O & RH 5.0 == seg fault...

11. Workshop 5.0 on solaris 8

12. Easter Egg in Early Access Solaris 5.0 Workshop/Compilers

13. compatibility between GCC and sun workshop 5.0 on Solaris 7