本文介绍了如何使用R和RCPP编译dll?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一个.cpp文件,我想将其编译为.dll以与R和RCPP一起使用. (不使用嵌入式程序包).我正在使用WinXP,R 2.13.2和RCPP 0.9.7.我正在使用Rtools 2.14.

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.

  1. 如何在minGW的搜索路径中包含Rcpp.h?我知道需要包含的文件在C:\ Program Files \ R \ R-2.13.2 \ library \ Rcpp \ include中.但是,我无法将"添加到添加"到搜索路径".

  1. 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".

我厌倦了一个临时的"hack".我将C:\ Program Files \ R \ R-2.13.2 \ library \ Rcpp \ include的内容复制到minGW的include目录中.编译/链接过程从myfile.cpp到myfile.o,但是在编译myfile.dll之前抛出了很多错误.

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.

我已将C:\ Program Files \ R \ R-2.13.2 \ bin \ i386添加到我的PATH中,并且正在WinXP命令提示符下调用R CMB SHLIB myfile.cpp.

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.

我该怎么办?

推荐答案

几个要点:

  1. MinGW中的gccg++编译器的行为与gcc系列中的其他编译器一样.这意味着没有添加到搜索路径":您使用-I/some/dir开关添加该路径和目录.同样,-L/some/lib将该目录添加到链接器路径.

  1. The gcc and g++ compilers from MinGW behave just like other compilers from the gcc 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.

确实要使用Makefile.我们的 Rcpp 软件包附带了许多示例.您可以查看ConvolveBenchmarks目录中的Makefile.

You really want to use a Makefile. Our Rcpp packages comes with lots of examples; you could look at the Makefile in the ConvolveBenchmarks directory.

但是您真正想要的是使用所谓的包".我们有一个完整的小插图 Rcpp-package 专门用于此.它可以像调用rcpp.package.skeleton()函数那样简单,该函数为您创建了包-并且动态库被创建为副作用.

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.

如果这一切太令人困惑,请先熟悉内联.使用verbose=TRUE参数查看内联如何构建动态库!

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!

最后,我们将其拼写为 Rcpp ,而不是RCPP.

Lastly, we spell it Rcpp, not RCPP.

rcpp-devel邮件列表也是很好的帮助来源.

The rcpp-devel mailing list is a good source of help too.

这篇关于如何使用R和RCPP编译dll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 06:32