2

Background

My company is thinking about bringing R into our work environment in conjunction with RStudio. As part of the security checks, we have to compile each of the different C/C++ files in a package to scan for possible security flaws. I know that the binaries are available, and I really wish that I could use them, but we have to compile ourselves. I have no R experience and a little experience with c++ from about 5 years ago. I'm trying to compile just the Rcpp C++ code and I don't know if this is possible.

What I've tried

I first tried to compile using VisualStudio and found it's not c99 compliant. I then tried cygwin and it didn't support w_strings. I have now installed ubuntu and am getting a lot of "undefined reference" errors when I compile. I know (or at least I believe) that Rcpp is designed to help use C++ in R. Given this, can I even compile some of these files as stand alone binary?

Some of the null references that I am getting while compiling api.cpp (I don't believe a complete list would provide any more information than the partial as it's quite long):

undefined reference to 'R_NilValue' undefined reference to 'REprintf' undefined reference to 'R_FlushConsole' undefined reference to 'Rf_install' undefined reference to 'Rf_setAttrib' undefined reference to 'Rf_mkChar' undefined reference to 'SET_STRING_ELT' undefined reference to 'Rf_allocVactor' undefined reference to 'R_ExternalPtrAddr' etc... 

Right now I assume that this isn't working because I'm not using Rcpp in the way in which it is intended and passing in any values. If I tried using another R package that uses Rcpp would that compile the Rcpp C++ files and leave the binaries? Is there anything that I can do short of just taking the binaries off of CRAN?

Solution

This was actually a relatively easy solution that I was unable to find anywhere else, although most people will simply be able to download the binary files so it won't matter.

1) Download from CRAN (not apt-get which did not work for me)

2) sudo tar -xvf Rcpp_X.XX.X.tar.gz

3) R CMD INSTALL Rcpp

This will create the binary .SO for you.

4
  • I don't think you want to use sudo to install a package. Commented Oct 21, 2014 at 17:07
  • @GSee So I got an "Error: no permission to install" message without sudo, but that could obviously be due to the security settings on my machine and not standard practice. I've edited it out just in case (and because it's obvious if you get the error). Commented Oct 21, 2014 at 17:55
  • you need to make yourself a member of the group that has write access to the directory where you're installing. Commented Oct 21, 2014 at 18:34
  • You can combine 2) and 3) as R CMD INSTALL ... happily uses a (compressed) tarball, and you can combine 1), 2) and 3) either from inside R via install.packages(), or, and that is my preference, by using install.r from the littler package. As @GSee states, ensure you are a member of the group owning the /usr/local/lib/R/site-library/ directory, and you won't even need sudo. Commented Oct 22, 2014 at 0:18

2 Answers 2

7

Quick ones:

  • It is spelled Rcpp, that is capital R followed by lowercase cpp. Like the file extension.

  • You made the heroic assumption that Rcpp can be compiled by Visual Studio [1]. It can't [2]. And we have documented this literally for years, i.e. at a minumum since late 2008 when I relaunched Rcpp.

  • See e.g. entries 1.3 and 2.9 from the Rcpp FAQ that comes with every download of Rcpp.

  • Ditto for Cygwin. R does not build under Cygwin. Hence don't try building Rcpp under Cygwin.

  • Last but not least: Not sure how closely you have looked at the Rcpp documentation, and what you think it is for. It is not some magic pony which converts R scripts into Windows binaries for you. No such pony exists. Rcpp is an extension package for R which makes R and C++ interchange easier. No more, no less. There are by now a few hundred Rcpp questions here so look around to get a feel.

All this is also almost surely a repeat question that could be closed but I don't have time to look now.

[1] Note the singular here, it is not plural "Visual Studios", or maybe you are referring to something other than the compiler and IDE by a company from the Pacific Northwest.

[2] Unless you are a genuine C++-on-Windows expert and willing to more-or-less build your own build system [3]

[3] All this is essentially due to R not being able to build with the VS toolchain. And $deity knows people have tried. The blame here lies on the side of the OS / compiler vendor for not following the standards which enable the R Core team to provide a consistent product on Windows (via gcc), OS X and essentially all flavour of Unix, including all Linux variants.

Sign up to request clarification or add additional context in comments.

7 Comments

@DirlEddelbuttel My mistake on the Rcpp vs RCPP. I now also fully understand that Visual Studio (singular) will not work and if that was the crux of my question, I would fully support closing it. However, I had read 1.3 and 2.9 after getting this error and finding the documentation. I was including it to fully enumerate what I've attempted and that is why I then added that I tried cygwin and am now trying Ubuntu. Thanks for your response.
I'm all for refocusing the question. You really should have no difficulty on Ubuntu -- apart from, and let me guess here, R maybe being unfamiliar to you. One installs via R CMD INSTALL ... which calls make and thereby the compiler. These aren't just libraries. I detail that in my Rcpp book if you're still curious...
Thank you for also clarifying that Rcpp is not a magic pony and that none exist. I was just trying to figure out if I could compile Rcpp cpp files as a stand alone files. Again, thanks for your response.
that last comment helps a lot! Thank you very much. I'll also check out the book.
You may want to look into RInside, another project of ours, which uses Rcpp as well and which allows you to use R inside of your C++ projects. But it isn't automatic either...
|
0

I tried compiling rcpp on Visual studio, and got to the point of 5 linking errors such as

unresolved external symbol Rf_allocVector and unresolved external symbol Rf_length

Do you know what file I made still need to add to the project to resolve the linking errors?

I did overcome compilation errors. I do not claim I have a complete answer, but I was not able to add this as a comment because my reputation score is not high enough.

I did a case sensitive whole word replacement of OUT -> RCPP_TYPE_OUT and Class -> RCPP_TYPE_Class.

Since I usually treat warnings as errors, I added the preprocessor macro

#define _CRT_SECURE_NO_WARNINGS #define __INTEL_COMPILER 

I also ignored warning 4996, and casted a size_t to int in one file.

Before including rcpp.h, I used #undef for macros ERROR, min, and max.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.