[R] Rinternals.h and iostream don't play nice together'

Dirk Eddelbuettel edd at debian.org
Mon Jan 31 00:20:40 CET 2005


On 30 January 2005 at 18:03, Faheem Mitha wrote:
| Consider the following file.
| 
| *******************************
| foo.cc
| *******************************
| #include <R.h>
| #include <Rinternals.h>
| #include <iostream>
| *******************************
| 
| R CMD SHLIB foo.cc

Two changes are required: You absolutely do need extern "C" ... to get C
headers in with C++, and the other is a simple reordering -- not sure where I
learned that can help at times ...

edd at basebud:/tmp> cat foo.cc
#include <iostream>
extern "C" {
  #include <R.h>
  #include <Rinternals.h>
}
edd at basebud:/tmp> R CMD SHLIB foo.cc
g++ -shared  -o foo.so foo.o   -L/usr/lib/R/lib -lR
edd at basebud:/tmp> ls -l foo.so
-rwxr-xr-x  1 edd edd 117872 Jan 30 17:16 foo.so
edd at basebud:/tmp>

Hth, Dirk

-- 
Better to have an approximate answer to the right question than a precise 
answer to the wrong question.  --  John Tukey as quoted by John Chambers




More information about the R-help mailing list