[R] compile error with C code and standalone R math C library

Dirk Eddelbuettel edd at debian.org
Sun Dec 14 07:15:02 CET 2003


On Sun, Dec 14, 2003 at 12:51:09AM -0500, Faheem Mitha wrote:
> On Sat, 13 Dec 2003, Dirk Eddelbuettel wrote:
> 
> > On Sat, Dec 13, 2003 at 07:44:46PM -0500, Faheem Mitha wrote:
> > > I just went back to an old piece of C code. On trying to compile it with
> > > the R math standalone C library I got the following error. Can anyone
> > > enlighten me what I am doing wrong, if anything? C file (rr-sa.c) follows.
> > >
> > > I'm on Debian sarge. I'm running R version 1.8.1. Gcc is version
> > > 3.3.1.
> > [...]
> > > faheem ~/co/rr/trunk>gcc -o rr rr-sa.c -lRmath -lm
> > > /usr/lib/gcc-lib/i486-linux/3.3.2/../../../libRmath.so: undefined
> > > reference to `Rlog1p'
> > > collect2: ld returned 1 exit status
> >
> > The linker tells you that it cannot find object code for a function Rlog1p.
> > So let's check:
> >
> > edd at chibud:~> grep Rlog1p /usr/include/Rmath.h
> > edd at chibud:~> grep log1p /usr/include/Rmath.h
> > double  log1p(double); /* = log(1+x) {care for small x} */
> > edd at chibud:~>
> >
> > Turns out that there is none defined in Rmath.h, but log1p exists.  This may
> > have gotten renamed since you first wrote your code.
> 
> Maybe I am being dense, but how is this my fault? I am not using either
> Rlog1p or log1p in my code (as far as I can see).

Indeed -- it looks like we have a problem. Looking at the NEWS file, some
logic regarding (R)log1p was changed in the 1.8.* series, and it seems to be
going wrong here.

As a stop gap-measure, just define an empty Rlog1p() to complete linking:

edd at chibud:/tmp> grep Rlog1p rr-sa.c
void Rlog1p(void) {;}
edd at chibud:/tmp> gcc -Wall -o rr rr-sa.c -lRmath -lm
edd at chibud:/tmp> ls -l rr
-rwxr-xr-x    1 edd      edd         13889 Dec 14 00:12 rr
edd at chibud:/tmp>

For the record, on my build system, a log1p function is found but deemed not
good enough:

edd at chibud:/tmp> grep log1p ~/src/debian/build-logs/r-base_1.8.1-1.log |
head -2checking for log1p... yes
checking for working log1p... no


Dirk

-- 
Those are my principles, and if you don't like them... well, I have others.
                                                -- Groucho Marx




More information about the R-help mailing list