# 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 Files\R\R-2.13.2\library\Rcpp\include. 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 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?

-

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.

-
Thank you for your prompt answer. I have encountered an error when trying to replicate the 'inline' example from your journal of statistical software paper. I am running the following code: src <- ' Rcpp::NumericVector xa(a); Rcpp::NumericVector xb(b); int n_xa = xa.size(), n_xb = xb.size(); Rcpp::NumericVector xab(n_xa + n_xb - 1); for (int i = 0; i < n_xa; i++) for (int j = 0; j < n_xb; j++) xab[i + j] += xa[i] * xb[j]; return xab; ' fun <- cxxfunction(signature(a = "numeric", b = "numeric"),src, plugin = "Rcpp", verbose=TRUE) –  power Oct 13 '11 at 0:17
I get the following errors: Compilation argument: C:/R/R-2.13.2/bin/i386/R CMD SHLIB file99a82.cpp 2> file99a82.cpp.err.txt ERROR(s) during compilation: source code errors or compiler configuration errors! Error in compileCode(f, code, language = language, verbose = verbose) : Compilation ERROR, function(s)/method(s) not created! In addition: Warning message: running command 'C:/R/R-2.13.2/bin/i386/R CMD SHLIB file99a82.cpp 2> file99a82.cpp.err.txt' had status 1 –  power Oct 13 '11 at 0:18
Where do I find this 'file99a82.cpp.err.txt ' to read the actual error messages? –  power Oct 13 '11 at 0:19
Also, is there a better way to reply to answers/questions? –  power Oct 13 '11 at 0:19
As I wrote in my initial answer, I would suggest that you subscribe to rcpp-devel and post there. –  Dirk Eddelbuettel Oct 13 '11 at 2:16
{"extraction_info": {"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.8393959999084473, "perplexity": 5182.5051635794225}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2015-35/segments/1440644064362.36/warc/CC-MAIN-20150827025424-00344-ip-10-171-96-226.ec2.internal.warc.gz"}