From ripley at stats.ox.ac.uk  Wed Nov  7 08:04:41 2007
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Wed, 7 Nov 2007 07:04:41 +0000 (GMT)
Subject: [Rd] problem in linking to libR.so with R 2.5.0
In-Reply-To: <40465.152.14.86.171.1194414361.squirrel@webmail.ncsu.edu>
References: <40465.152.14.86.171.1194414361.squirrel@webmail.ncsu.edu>
Message-ID: <Pine.LNX.4.64.0711070700110.3462@gannet.stats.ox.ac.uk>

IOStuff.h is not a public header, and neither are the entry points within 
it.  See 'Writing R Extensions'.  One is in the category:

   Entry points that are where possible (Windows and some modern Unix
   compilers/loaders when using @R{} as a shared library) not exported.


On Wed, 7 Nov 2007, Jiangtian Li wrote:

> Dear All,
>
> I tried to write a C++ program that uses R internals and I encounter
> "undefined reference" error when linking to libR.so. Here is an small
> example of the program test.cpp:
>
> extern "C" {
> #include <config.h>
> #include <IOStuff.h>
>
> int main(int argc, char** argv)
> {
>  R_IoBufferInit(&R_ConsoleIob);
>  return 0;
> }
> }
>
> I built it using:
> g++ -o test -I/dir/to/R-2.5.0/src/include -L/dir/to/R-2.5.0/lib/R/lib -lR
> test.cpp

You need -I/dir/to/R-2.5.0/include to get the public headers.

> and I got the error message:
>
> /tmp/cc4zxrqh.o(.text+0x20): In function `main':
> test.cpp: undefined reference to `R_ConsoleIob'
> /tmp/cc4zxrqh.o(.text+0x25):test.cpp: undefined reference to `R_IoBufferInit'
> collect2: ld returned 1 exit status
>
> I installed R 2.5.0 on Fedora Core 4 with gcc 4.0.2 and configured with
> --prefix=/dir/to/R-2.5.0 --enable-R-shlib
>
> I did that with R 2.2.1 and can build without problem. Any suggestion on
> how to link to libR.so in later R versions? Your help is very appreciated.
>
> Best regards,
> Jiangtian
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
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



[Rd] problem in linking to libR.so with R 2.5.0
Prof Brian Ripley