[R] rtools fstream error

William Dunlap wdunlap at tibco.com
Mon Feb 2 22:29:19 CET 2015


Try adding the line
  #define R_NO_REMAP
to the top of your file (before any #include's) so the R
include files don't define length(x).

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Mon, Feb 2, 2015 at 1:11 PM, <sunaga at telenet.be> wrote:

> Hi,
>
> when writing a simple cpp function to be run in R I obtain a compilation
> error as soon as I include fstream. Any hints of what goes wrong and how to
> fix it? It's Windows 7 64-bit, R-3.1.2 and Rtools32. An example to recreate
> the error:
>
>     #include <R.h>
>     #include <Rdefines.h>
>     #include <fstream>
>     using namespace std;
>
>     extern "C" SEXP test(SEXP x) {
>       SEXP result;
>
>       PROTECT(result = allocVector(REALSXP,1));
>       REAL(result)[0] = REAL(x)[0]*5;
>
>       UNPROTECT(1);
>       return result;
>     }
>
> Output:
>
>     > R CMD SHLIB test.cpp
>     g++ -m64 -I"C:/PROGRA~1/R/R-31~1.2/include" -DNDEBUG
>  -I"d:/RCompile/CRANpkg/
>     extralibs64/local/include"     -O2 -Wall  -mtune=core2 -c test.cpp -o
> test.o
>     In file included from
> c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/
>     ../../../../include/c++/4.6.3/fstream:42:0,
>                      from test.cpp:3:
>
> c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../include/c+
>     +/4.6.3/bits/codecvt.h:216:45: error: macro "length" passed 4
> arguments, but tak
>     es just 1
>     In file included from
> c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/
>     ../../../../include/c++/4.6.3/fstream:921:0,
>                      from test.cpp:3:
>
> c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../include/c+
>     +/4.6.3/bits/fstream.tcc:826:60: error: macro "length" passed 4
> arguments, but t
>     akes just 1
>
> c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../include/c+
>     +/4.6.3/bits/fstream.tcc:943:39: error: macro "length" passed 4
> arguments, but t
>     akes just 1
>     In file included from
> c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/
>     ../../../../include/c++/4.6.3/fstream:42:0,
>                      from test.cpp:3:
>
> c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../include/c+
>     +/4.6.3/bits/codecvt.h:215:7: error: expected ';' at end of member
> declaration
>
> c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../include/c+
>     +/4.6.3/bits/codecvt.h:217:7: error: expected unqualified-id before
> '{' token
>     make: *** [test.o] Error 1
>
> Thanks,
> sunaga
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list