[R] simple example of C interface to R

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Feb 8 23:16:42 CET 2005


On Tue, 8 Feb 2005 jbdunsmo at utmb.edu wrote:

> thanks for all the help.  i've tried everyone's suggestions, to no
> avail...

Not *my* suggestion, though.  Mine was to use the Makefile, which has

Rtest: Rtest.o embeddedRCall.o
         $(R_CMD_LINK) -o $@ Rtest.o embeddedRCall.o $(LIBR)

and just needs the correction I mentioned.


> On Tue, Feb 08, 2005 at 04:19:10PM -0500, Huntsinger, Reid wrote:
>> Rtest.o is just an object file, and the second call to gcc is really a call
>> to ld and creates Rtest.so, a shared library. Neither is executable.
>> Probably you want to compile Rtest.c into an executable; it does have the
>> "main" function after all. Perhaps
>>
>> gcc -L/usr/local/lib -o Rtest Rtest.o   -L/usr/lib/R/bin -lR
>>
>> would work.
>
> that didn't work:
>
>    $ gcc -L/usr/local/lib -o Rtest Rtest.o   -L/usr/lib/R/bin -lR
>    Rtest.o(.text+0x2f): In function `main':
>    : undefined reference to `eval_R_command'
>    collect2: ld returned 1 exit status
>
>
> On Tue, Feb 08, 2005 at 11:40:08AM -0800, Duncan Temple Lang wrote:
>>
>> The .o file is object code that is then used when creating an
>> executable.   You cannot run it directly.
>> You can use the Makefile in that tests/Embedding/ directory
>> to build the Rtest application for you.
>
>    $ cd R-1.9.0/tests/Embedding/
>    $ ./configure
>    -/bin/bash: ./configure: No such file or directory
>    $ make
>    make: *** No targets specified and no makefile found.  Stop.
>    $ aclocal
>    aclocal-1.9: `configure.ac' or `configure.in' is required
>    $ automake
>    automake-1.9: `configure.ac' or `configure.in' is required
>    $ autoconf
>    autoconf-2.59: no input file
>
> do i have to write my own configure script?
>
>
> On Tue, Feb 08, 2005 at 09:42:59PM +0000, Prof Brian Ripley wrote:
>> Did none of you notice the Makefile in that directory?
>>
>> Should be -L`R RHOME`/lib for R>=2.0.0 (and that Makefile needs
>> updating).
>> From ONEWS
>>
>>     o   The dynamic libraries libR and libRlapack are now installed
>>     in
>>         R_HOME/lib rather than R_HOME/bin.
>>
>> You may also need to set LD_LIBRARY_PATH: I do to include
>> /usr/local/lib.
>>
>
>    $ gcc -L`R RHOME`/lib -o Rtest Rtest.o -L/usr/lib/R/bin/ -lR
>    Rtest.o(.text+0x2f): In function `main':
>    : undefined reference to `eval_R_command'
>    collect2: ld returned 1 exit status
>
>
> it looks like someone's going to have to spell it out for me.
>
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list