I'm developing under Sparc Solaris 2.6, SC 4.2 (from Visual Workshop 3.0).
I'm trying to create a shared library and use threads (-lpthread). The
problem is that I can do one or the other, but not both. I have a little
test program that calls some functions in my little test shared library. The
library will make pthread calls, and the application may make pthread calls.
If I link -lpthread, when my program calls fopen(), the program halts with
the following error message:
libc internal error: _rmutex_unlock: rmutex not held.
If I do not link with pthread, then my program runs ok, but the pthread calls
are apparently stubbed out by libc.
Of course, if I create my library non-shared (ar/ranlib style), then there is
no problem. But that is not a practical solution for our application. I
need to be able to successfully use shared libraries with -lpthread.
I've enclosed my makefile below, as I suspect that I'm doing something wrong
there. Any suggestions are most appreciated (especially source for a test
app, lib, makefile that shows me how it's done :-)
all: libfoo.so foo foomt
# CC -G -o libfoo.so foolib.o -lpthread
CC -G -o libfoo.so foolib.o
cp libfoo.so /usr/lib/libfoo.so
foolib.o: foolib.cpp foolib.h
foomt: foo.o libfoo.so
CC -o foomt foo.o -lfoo -lpthread
foo: foo.o libfoo.so
CC -o foo foo.o -lfoo
foo.o: foolib.h foo.cpp
rm foo.o foolib.o libfoo.so foo foomt
"Well? Does anyone want to punch me in the throat?" - R. Parker