R 尝试编译时抛出错误
我正在尝试使用 R 生成 2 个文件,第一个文件实际上生成得很好,但第二个文件告诉我以下内容:
conteo_correlaciones.c:3:15:错误:Rh:没有这样的文件或目录 conteo_correlaciones.c:4:24:错误:Rinternals.h:没有这样的文件或 目录 conteo_correlaciones.c:31: 错误: 预期为 '=', ',', ';', “countcorrelations”之前的“asm”或“属性”
Rh 和 Rinternals.h 都是从 R 目录复制的,它们与其余文件位于同一目录中,但我无法获取过去这个错误,这些文件被这样的包含调用:
#include <R.h>
#include <Rinternals.h>
我在终端中所做的是:
R CMD SHLIB conteo_correlaciones.c
哪个工作很好并生成正确的文件并且:
gcc -dynamiclib conteo_correlaciones.c -o conteo_correlaciones.so
哪个向我抛出了上述错误。知道会是什么吗?
I am trying to use R to generate 2 files the first one actually generates pretty good but the 2nd one tells me the following:
conteo_correlaciones.c:3:15: error: R.h: No such file or directory
conteo_correlaciones.c:4:24: error: Rinternals.h: No such file or
directory conteo_correlaciones.c:31: error: expected ‘=’, ‘,’, ‘;’,
‘asm’ or ‘attribute’ before ‘countcorrelations’
both R.h and Rinternals.h were copied from the R directory and they're in the same directory that the rest of the files but I can't get past this error, these files are being called by an include like this:
#include <R.h>
#include <Rinternals.h>
and what I'm doing in the terminal is:
R CMD SHLIB conteo_correlaciones.c
Which works great and generates me the correct file and:
gcc -dynamiclib conteo_correlaciones.c -o conteo_correlaciones.so
Which throws me the aforementioned error. Any idea what could be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
R CMD SHLIB
添加所有适当的标志来编译您的代码。您无法(可靠地)“手动”编译代码。R CMD SHLIB
已经创建了所有必需的文件,因此您不需要自己运行gcc
。例如,这就是 R CMD SHLIB 运行的内容:
如您所见,创建正确的二进制文件需要一长串标志。第一行是编译,第二行是链接。正如您所看到的,它甚至与您尝试“手动”执行的操作相差甚远。
至于确切的错误 - 这只是您会得到的众多错误之一 - 在上述情况下,您需要使用
-I
包含 R 的包含路径。还有其他的,所以你不想去那里,只需坚持使用 R CMD SHLIB 即可。R CMD SHLIB
adds all appropriate flags to compile your code. You cannot (reliably) compile your code "by hand".R CMD SHLIB
already creates all necessary files, so you don't need to rungcc
yourself.For example, this is what
R CMD SHLIB
runs:As you can see there is a long list of flags that are needed to create the proper binary. The first line is the compilation, the second one is linking. As you can see it's not even close to what you were trying to do "by hand".
As for the exact error - it's just one of many that you would get - in the above case you need to include R's include path with
-I
. There are others as well, so you don't want to go there, just stick withR CMD SHLIB
.必须进行更改
。
如果头文件与代码文件位于同一目录中,则
或者您可以将正确的包含路径添加到 gcc 命令行(例如
-I/usr/share/R/include
)。You have to change
to
if the header files are in the same directory like your code files.
Or you could add the correct include-path to gcc commandline (e.g.
-I/usr/share/R/include
).首先找到 Rh 的存储位置(它可以位于 /usr/include 或 /usr/local/include 中,或者如果 R 是从源安装的,则可以位于任何位置)。就我而言,它位于 /home/user/R/include/ 中:
然后导出路径:
然后编译应该可以正常运行。
First locate where R.h is stored (it could be in /usr/include or /usr/local/include or anywhere if R has been installed from sources). In my case it is in /home/user/R/include/:
Then export the paths:
The compilation should then run fine.