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

北城余情 提交于 2019-12-01 03:58:35

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.

damienfrancois

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

Another way is to specify some environment variables to directly use the include path:

export CPATH=/usr/lib64/R/include/
export C_INCLUDE_PATH=/usr/lib64/R/include/
export CPLUS_INCLUDE_PATH=/usr/lib64/R/include/
export GCC_INCLUDE_DIR=/usr/lib64/R/include/

This should then run fine:

gcc -o rand_beta rand_beta.c
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!