Author Topic: [SOLVED] Anybody using R? Building a shared library for dynamic loading.  (Read 1286 times)

Offline Socratea

  • Full Member
  • ***
  • Posts: 156
  • Noob is as noob does
I was wondering if anyone on the forum was using R?

I am compiling c codes for use in R, but for some wierd reason they wont compile if I include a header file.

lets says I have the following saved as test.c

Code: [Select]
#include < R.h >
/* including the header R.h */
#include < stdio.h >

/*must be void as the function should not return anything*/
void twoloop(int *startOne, int *stopOne, int *stepOne, int *startTwo, int *stopTwo, int *stepTwo)
{
 int i,j;
 for(i = *startOne; i < *stopOne+1; i = i + *stepOne)
 for(j = *startTwo; j < *stopTwo+1; j = j + *stepTwo)
 Rprintf("Parameter one is %d and Parameter two is %d\n", i, j);
}

Then when I want to build shared library for dynamic loading using "R CMD SHLIB test.c", I get this:

gcc -std=gnu99 -I/usr/lib/R/include  -I/usr/local/include    -fpic  -O2  -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fomit-frame-pointer -march=i586 -mtune=generic -fasynchronous-unwind-tables -c twoloops.c -o twoloops.o
twoloops.c:1:17: fatal error:  R.h : No such file or directory
compilation terminated.
make: *** [twoloops.o] Error 1

The file however exists, I can confirm that. Whats Up? Does anyone know what I am missing?
« Last Edit: June 12, 2011, 11:19:11 AM by Writhen »

Only those that choose a different path from
the others become great and infinite.

.

Offline AS

  • Hero Member
  • *****
  • Posts: 4111
  • Have a nice ... night!
Re: Anybody using R? Building a shared library for dynamic loading.
« Reply #1 on: June 11, 2011, 07:17:35 AM »
Hi Writhen,

remove the spaces before and after the header filenames:

Quote
#include < R.h >
/* including the header R.h */
#include < stdio.h >

change to:
Quote
#include <R.h>
/* including the header R.h */
#include <stdio.h>

AS

Online muungwana

  • Hero Member
  • *****
  • Posts: 6205
Re: Anybody using R? Building a shared library for dynamic loading.
« Reply #2 on: June 11, 2011, 07:24:29 AM »

where exactly is "R.h" in your file system? i.e what is the full path to the file?
.. 3 things are certain in life : death, taxes and software bloat ..
.. tell me something i don't know, something i can use as i struggle to reason with the world around me ..

Offline Socratea

  • Full Member
  • ***
  • Posts: 156
  • Noob is as noob does
Re: Anybody using R? Building a shared library for dynamic loading.
« Reply #3 on: June 11, 2011, 07:37:44 AM »
Incredible! Such a silly error, I just could not understand why it did not work. Thanks as, to the rescue as usual :)

muungwana; the full path was /usr/lib/R/include - but the error was caused by the careless coding on my part... extra spaces  ::)
« Last Edit: June 12, 2011, 11:18:03 AM by Writhen »

Only those that choose a different path from
the others become great and infinite.

.