[Rd] R's --enable-threads does nothing?; gdb needs -lpthread
Andrew Piskorski
atp at piskorski.com
Mon Oct 5 23:22:02 CEST 2009
In the R-2-9-branch (svn revision 49914, 2009-09-24), R's configure
script has an "--enable-threads" option. But, does it do anything
useful? When I use "--enable-threads=posix", some of the configure
output changes slightly, but it seems to have no effect on the actual
link commands used when building R. Is that a bug, or am I
misunderstanding what it's supposed to do?
Btw, ldd said that exactly these 4 objects are linked against
libpthread.so.0, regardless of whether I use --enable-threads or not:
./lib/R/modules/x86_64/R_X11.so
./lib/R/library/tcltk/libs/x86_64/tcltk.so
./lib/R/site-library/bigmemory/libs/x86_64/bigmemory.so
./lib/R/site-library/Rmpi/libs/x86_64/Rmpi.so
Next I tried setting the "LIBS=-lpthread" environment variable when
calling configure - that works. (Perhaps I should have also set
FLIBS, I'm not sure.) The generated Makeconf file now has this:
LIBS = -ldl -lm -lpthread
and building with that links my libR.so against libpthread.so.0, which
fixes the gdb problem described below. Is there any reason you know
of NOT to link R with -lpthread on Linux, any potential downside?
Now, why do I care about this -lpthread stuff in the first place?
It's to work around a gdb limitation.
I have a custom library of C code which I use from R, and my library
needs to be linked with -lpthread. I know that R isn't thread-safe,
and my code is not itself using threads, but it in turn statically
links in some lower level libraries which insist on having the
-lpthread.
That has worked fine for me for a long time, no problems, except that
gdb won't work! When I run R under the debugger with "R -d gdb", gdb
only works if my own linked-with-pthread package is NOT loaded. As
soon as I load it, gdb stops with this error:
[Thread debugging using libthread_db enabled]
Error while reading shared library symbols:
Cannot find new threads: generic error
Googling says that happens because the R binary starts out without
thread support, and gdb doesn't know what to do when my *.so suddenly
brings in the thread stuff. Since I can't stop using -lpthread in my
library, the obvious fix is for me to build R itself with -lpthread,
so gdb doesn't get confused.
--
Andrew Piskorski <atp at piskorski.com>
http://www.piskorski.com/
More information about the R-devel
mailing list