如何使用 R 和 RCPP 编译 dll?
我已经编写了一个 .cpp 文件,我想将其编译为 .dll 以与 R 和 RCPP 一起使用。 (不使用内联包)。 我使用的是 WinXP 和 R 2.13.2 以及 RCPP 0.9.7。我正在使用 Rtools 2.14。
如何将 Rcpp.h 包含在 minGW 的搜索路径中?我知道我需要包含的文件位于 C:\Program Files\R\R-2.13.2\library\Rcpp\include 中。但是,我无法添加将它们“添加”到“搜索路径”。
我厌倦了暂时的“黑客”。我将 C:\Program Files\R\R-2.13.2\library\Rcpp\include 的内容复制到 minGW 的 include 目录中。编译/链接过程从 myfile.cpp 到 myfile.o,但在编译 myfile.dll 之前抛出了一堆错误。
我已将 C:\Program Files\R\R-2.13.2\bin\i386 添加到我的 PATH 中,并从 WinXP 命令提示符调用 R CMB SHLIB myfile.cpp。
我应该做什么?
I have written a .cpp file and I want to compile it to a .dll for use with R and RCPP. (without using the inline package).
I am using WinXP and R 2.13.2 and RCPP 0.9.7. I am using Rtools 2.14.
How do I include Rcpp.h in minGW's search path? I underastand that the files that I need to include are in C:\Program Files\R\R-2.13.2\library\Rcpp\include. However, I was not able to add the to "add" them to "search path".
I tired a temporary "hack". I copied the contents of C:\Program Files\R\R-2.13.2\library\Rcpp\include into minGW's include directory. The compiling/linking process gets from myfile.cpp to myfile.o but throws a bunch of errors before it can compile myfile.dll.
I have added C:\Program Files\R\R-2.13.2\bin\i386 to my PATH and I am calling R CMB SHLIB myfile.cpp from the WinXP command prompt.
What should I be doing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几点要点:
MinGW 的
gcc
和g++
编译器的行为与gcc
系列的其他编译器一样。这意味着没有“添加到搜索路径”:您可以使用 -I/some/dir 开关来添加该路径和目录。同样,-L/some/lib
将该目录添加到链接器路径中。您确实想要使用
Makefile
。我们的 Rcpp 包附带了很多示例;您可以查看ConvolveBenchmarks
目录中的Makefile
。但你真正想要的是使用所谓的“包”。我们有一个完整的小插图 Rcpp-package 致力于此。它可以像调用 rcpp.package.sculpture() 函数一样简单,该函数会为您创建包,并且会创建动态库作为副作用。
如果这一切都太令人困惑,请先尝试熟悉内联。使用
verbose=TRUE
参数来查看内联如何构建动态库!最后,我们将其拼写为Rcpp,而不是RCPP。
rcpp-devel 邮件列表也是一个很好的帮助来源。
A couple of quick points:
The
gcc
andg++
compilers from MinGW behave just like other compilers from thegcc
family. That means there is no 'add to search path': you use the-I/some/dir
switch to add that path and directory. Similarly,-L/some/lib
adds that directory to the linker path.You really want to use a
Makefile
. Our Rcpp packages comes with lots of examples; you could look at theMakefile
in theConvolveBenchmarks
directory.But what you really want is to use so-called "package". We have an entire vignette Rcpp-package devoted to this. It can be as simple as calling the
rcpp.package.skeleton()
function which creates the package for you---and the dynamic library gets created as a side-effect.If all this is too confusing, try getting familiar with inline first. Use the
verbose=TRUE
argument to see how inline builds the dynamic library!Lastly, we spell it Rcpp, not RCPP.
The
rcpp-devel
mailing list is a good source of help too.