[Rd] Detecting compilation under R

Paul Roebuck roebuck at mdanderson.org
Wed Dec 20 00:12:25 CET 2006


On Thu, 14 Dec 2006, Prof Brian Ripley wrote:

> On Thu, 14 Dec 2006, Barry Rowlingson wrote:
>
> [Silently discarding the answer to his question, and breaching
> 'fair use' copyright provisions.]
>
> >> So the problem is that you needed rather
> >>
> >> #include <R.h>
> >> #ifdef USING_R
> >> x = rand_unif(0.0,1.0);
> >> #else
> >> #include <gsl_random.h>
> >> x = gsl_runif(0.0,1.0);
> >> #endif
> >>
> >> since if R.h is not around, the include will not include it.
>
> > If R.h is not around, the preprocessor will throw a tantrum:
>
> If *no* R.h is around: easy to solve.
>
> > cc    -c -o simple.o simple.c
> > simple.c:2:15: error: R.h: No such file or directory
> >
> [SNIP - PLR]

Never saw the reply to Barry's question. His quoting
methodology notwithstanding, I don't see the answer
plainly either.

When Prof. Ripley says above - "easy to solve", is the
implication that R installation become prerequisite or
creating a fake "R.h"?


Would have thought it easiest to solve by adding
-DUSING_R to Makevar's PKG_CPPFLAGS with the code
restructured as below.

#ifdef USING_R
    #include <R.h>
    x = rand_unif(0.0,1.0);
#else
    #include <gsl_random.h>
    x = gsl_runif(0.0,1.0);
#endif

Barry's suggestion to eliminate this step by having any
R-based compile process identify itself (although a single
preprocessor define is sufficient) would be a nice addition,
simplifying life when a source file can be used with
R or standalone.

----------------------------------------------------------
SIGSIG -- signature too long (core dumped)



More information about the R-devel mailing list