Stuart Henderson wrote:
> On 2009/12/02 02:42, Stuart Cassoff wrote:
>> Stuart Cassoff wrote:
>>> Stuart Henderson wrote:
>>>> On 2009/10/29 22:32, Stuart Cassoff wrote:
>>>>> I understand about -lpthread, but this is the result without it.
>>>> we use -pthread not -lpthread
>>> I'd be extremely happy to know how I can make this work without -lpthread.
>>>
>>> Stu
>>
>> I don't seem to be able to figure this out and could use some help.
>> Here is something demonstrating the situation.
> 
> Ahh. The tclsh you're running it from isn't linked with pthreads. If you
> switch to the -threaded flavor of Tcl this will work.
> 
> $ cc -Wall -pthread -shared -L/usr/local/lib -ltclstub85 -ldbus-1 -o 
> libqz69.so.0.0 qz.o
> $ tclsh8.5
> % load ./libqz69.so.0.0
> %
>

I'll try not to ramble here:
1) A shared object that gets [load]ed into a Tcl interpreter must be linked with
any needed libs, as the program that created the interpreter may not be linked 
with
those libs.
2) On OpenBSD libpthread is special and one should not link to it directly, 
rather
one should use the -pthread flag when compiling and linking and the magical 
pthread
elves take care of making things work.
3) Dynamic linking/loading : I understand to some degree.
4) Threads : I know what they are, but that's about it.
5) Threaded Tcl on OpenBSD does not work very well: it doesn't build properly
(lack of -pthread and it links the lib with -lpthread) and even if that's
fixed there'll still be errors and segfaults running the regression tests.
I'd like for threaded Tcl to be the default one day, but that day is not soon.

So, 2) conflicts with 1) but see 4) and 3).

1) can be demonstrated thusly:
$ cc -Wall -pthread -shared -L/usr/local/lib -ltclstub85 -lpng -o 
libqz69.so.0.0 qz.o
That will fail to load because libz is also needed; add -lz to make it work.


So what can be done? Looking at 5) we have to rule out threaded Tcl for now.
Non-threaded Tcl can be built with -pthread and that will work but now Tcl
is linked to libpthread in the event that someone loads a libpthread-requiring 
.so,
which imho is not so great.


Though this solves the problem for Tcl (Tk would also probably have to be built 
likewise),
it does not solve it for anything that embeds a Tcl interpreter.


$ cat m.c
#include <tcl.h>
int main (int argc, char *argv[]) {
  Tcl_Interp *interp;
  Tcl_FindExecutable(argv[0]);
  interp = Tcl_CreateInterp();
  Tcl_Init(interp);
  if (argc > 1)
    Tcl_EvalFile(interp, argv[1]);
  return 0;
}


$ cat m1.tcl
puts m1


$ cat m2.tcl
load ./libqz69.so.0.0
puts m2


$ cc -Wall -I/usr/local/include/tcl8.5 -L/usr/local/lib -ltcl85 m.c


$ ./a.out m1.tcl
m1


$ ./a.out m2.tcl
./a.out:/usr/local/lib/libdbus-1.so.7.1: undefined symbol 'pthread_cond_signal'
    ...
./a.out:/usr/local/lib/libdbus-1.so.7.1: undefined symbol 
'pthread_cond_timedwait'
m2


$ cc -Wall -pthread -I/usr/local/include/tcl8.5 -L/usr/local/lib -ltcl85 m.c

$ ./a.out m2.tcl
m2


>From all this, the only way I can see to resolve this is either:
a) Link whatever needs libpthread using -lpthread
b) Build everything that embeds a Tcl interpreter with -pthread
needlessly in case something is loaded that needs libpthread.
c) Inquire with the magic pthread elves for guidance and assistance.


Whew! Thank-you for your time,
Stu

Reply via email to