问题
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.
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/26486700/compiling-the-rcpp-package