[R] interfacing R and c++

ripley@stats.ox.ac.uk ripley@stats.ox.ac.uk
Wed, 3 Jul 2002 17:04:10 +0100 (BST)


On Wed, 3 Jul 2002, Martin Maechler wrote:

> >>>>> "NancyW" == Wong, Nancy Diana <nancy_wong@merck.com> writes:
>
>     NancyW> Hi Martin,
>
>     NancyW> Thanks for the quick response.  This is the compile
>     NancyW> error I'm getting:
>
>     NancyW> g++ -g -Wall -DDEBUG -I. -I/usr/local/include/vigra
>     NancyW> -I/home/reid/install-these/vigra1.1.4/include -I/usr/local/lib/R/include -c
>     NancyW> main.c
>     NancyW> In file included from /usr/local/lib/R/include/R.h:45,
>     NancyW> from main.c:23:
>     NancyW> /usr/local/lib/R/include/R_ext/Boolean.h:29: `enum {anonymous} FALSE'
>     NancyW> redeclared as different kind of symbol
>     NancyW> /usr/lib/qt/include/qglobal.h:381: previous declaration of `const bool
>     NancyW> FALSE'
>     NancyW> /usr/local/lib/R/include/R_ext/Boolean.h:29: `enum {anonymous} TRUE'
>     NancyW> redeclared as different kind of symbol
>     NancyW> /usr/lib/qt/include/qglobal.h:382: previous declaration of `const bool TRUE'
>     NancyW> In file included from main.c:24:
>     NancyW> /usr/local/lib/R/include/Rinternals.h:820: parse error before `1'
>     NancyW> make: *** [main.o] Error 1
>
>     NancyW> when I try to include R.h and Rinternals.h
>
> Ok, so we see it's a real conflict with TRUE and FALSE being
> defined both
>  in R's   R_ext/Boolean.h  and
>  in qt's  qglobal.h
>
> i.e. both R and qt assume that TRUE/FALSE are not yet defined
> and do define them.
>
> For the moment you'll have to fix this up manually, e.g. by
> adding an
> #ifndef TRUE
> ....
> ....
> #endif
>
> around the definition in either (or both!) of the two include files.

I think the definitions are different, and they are not #defines.

This comes up all the time with Windows headers.  Usually you need to
include the one you do not need first, then #undef some conflicts
and include the other.  But qglobal is not using a #define, so you can
I think use something like

#include <qt.h>
#define TRUE R_TRUE
#define FALSE R_FALSE
#include <R.h>

> For R 1.6.0, we should try to prevent this (and the Qt
> developers should too ..).
> Proposals welcome.

I don't see how, except via the above define trick.

-- 
Brian D. Ripley,                  ripley@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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._