Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install/locate R.h and Rmath.h header files?

Tags:

header-files

r

I am trying to compile some C code (called rand_beta) in terminal which contains the lines to include R.h and Rmath.h header files using gcc -o rand_beta rand_beta.c so I can then call the code from within R. However, I get the error messages:

rand_beta.c:1:15: error: R.h: No such file or directory
rand_beta.c:2:19: error: Rmath.h: No such file or directory

It seems that these header files which should come installed with R are not on my system.

Can someone guide me as to how I can get my computer to find the R header files? Do I need to download them from somewhere?

like image 680
user3018658 Avatar asked Nov 21 '13 17:11

user3018658


People also ask

How do I add a header file in Makefile?

The only way to include the header file is to treat the filename in the same way you treat a string. Makefiles are a UNIX thing, not a programming language thing Makefiles contain UNIX commands and will run them in a specified sequence.

HOW include header file in C Linux?

To import a header, use the #include, a preprocessor directive telling the compiler that it should import and process the code before compiling the rest of the code. On a typical C program, it should contain the stdio. h header file, which is the standard header file for input and output streams.

How do I find header files?

Most standard headers are stored in /usr/include . It looks like stdbool. h is stored somewhere else, and depends on which compiler you are using. For example, g++ stores it in /usr/include/c++/4.7.

Where are GCC header files located?

GCC looks for headers requested with #include " file " first in the directory containing the current file, then in the directories as specified by -iquote options, then in the same places it would have looked for a header requested with angle brackets. For example, if /usr/include/sys/stat. h contains #include "types.


2 Answers

The other answers try to guess where your R installation directory is. But there is a more robust solution. Use the R.home command in R to find it wherever it is:

> R.home('include')
/usr/lib64/R/include

That is the folder containing R.h and Rmath.h on my system. Your folder may be in a different place.

like image 139
drhagen Avatar answered Oct 13 '22 12:10

drhagen


You first need to locate those headers. In my system, they are located in /usr/lib64/R/include/R.h, part of the R-devel package I installed with yum.

Then use the -I option of gcc to tell gcc where to find them.

gcc -I/usr/lib64/R/include  -o rand_beta rand_beta.c

Then, you will also most probably need to export LD_LIBRARY_PATH to run your compiled program:

LD_LIBRARY_PATH=/usr/lib64/R/lib ./rand_beta
like image 7
damienfrancois Avatar answered Oct 13 '22 11:10

damienfrancois