Skip to content
Prev 5018 / 10988 Next

[Rcpp-devel] undefined symbol: clock_gettime in Rcpp 0.10.2

Just a guess.

Is it possible that this is caused by the way how R was built? Since you are using clang and R unstable, it is clear that you build R yourself.
ldd libR.so
shows among other things librt. In other words, librt was loaded when R was started. However building Rcpp only builds libraries rather than executables, and thus there shouldn't be errors when building Rcpp while loading Rcpp may cause errors unless librt was already loaded or linked to libRcpp.so

Another reason that I suspect that this is not a problem with compiler but how R is built is that, try the following program,

#include <time.h>

int main ()
{
    clock_gettime(0,0);
}

with either g++ or clang++, without explicit linking to -lrt, the same undefined symbol error occurs. For instance, on my RHEL, with g++ 4.4,
$ g++ -o foo foo.cpp 
/tmp/ccKB2Ftv.o: In function `main':
foo.cpp:(.text+0xf): undefined reference to `clock_gettime'
collect2: ld returned 1 exit status

Change main to say, foo, and build a shared or static library without linking to librt causes no problems at all (though loading that library will cause problems as usual).

If so far what I am talking is not non-sense, then I suggest you find your libR.so library, and check if it indeed does not link to librt. If that is the case, we need to find out how to build R to trigger the linking to librt (build R with profiling, which is the default?)

Anyway, as Dirk said, linking to librt is harmless on Linux nonetheless, so that is perhaps the easiest 'fix'.

Best,

Yan Zhou
On Dec 24, 2012, at 1:11 PM, Dirk Eddelbuettel <edd at debian.org> wrote: