Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

c++ - How do I compile a dll with R and RCPP?

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. 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 FilesRR-2.13.2libraryRcppinclude. However, I was not able to add the to "add" them to "search path".

  2. I tired a temporary "hack". I copied the contents of C:Program FilesRR-2.13.2libraryRcppinclude 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 FilesRR-2.13.2ini386 to my PATH and I am calling R CMB SHLIB myfile.cpp from the WinXP command prompt.

What should I be doing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

A couple of quick points:

  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.

  2. 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.

  3. 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.

  4. 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!

  5. Lastly, we spell it Rcpp, not RCPP.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...