[Rcpp-devel] Creating a Rcpp package : Visual C++ Library error
Valentin Mansion
valentin.mansion at laposte.net
Wed Jul 18 04:01:22 CEST 2012
Hi everyone,
I have an issue when creating a package using Rcpp, on a Windows7,
32bits computer. I haven’t found anything on the net or help pdfs that
looks like my error, so maybe you can help me.
I have used the Rcpp.package.skeleton function with the
example_code=TRUE argument, in order to see how Rcpp functions have to
be written when creating a package. When I create the package
containing the “Rcpp_hello_world” function, apart from a few error
messages due to poor documentation, it works: the function returns
good results (a list with “1” “2”,”foo” ”bar”).
However, when I try to put a function that I created in the package, I
have a Microsoft Visual C++ Library error message. The function works
fine when I run it using the inline package (it sums the elements of a
vector, and ignores the NAs if any), so it must be something with the
files that I added in the package. These files are:
-a sum2cpp.h file in the “src” folder,
#ifndef _starFMcpp_SUM2CPP_H
#define _starFMcpp_SUM2CPP_H
#include <Rcpp.h>
RcppExport SEXP sum2cpp(SEXP x) ;
#endif
-a sum2cpp.cpp file, in the “src” folder,
#include "sum2cpp.h"
SEXP sum2cpp(SEXP x) {
using namespace Rcpp ;
Rcpp::NumericVector vect(x);
int sizeVect = vect.size();
double sum2(0.);
for (int i = 0; i < sizeVect; ++i) {
if ( is_na(vect)[i]==false ) { sum2=sum2+vect[i]; }
}
return(Rcpp::wrap(sum2));
}
-a sum2cpp.R file in the R folder.
sum2cpp <- function (x) {.Call( "sum2cpp", PACKAGE = "starFMcpp" )}
After I do R CMD build, R CMD check and R CMD INSTALL, I am able to
load my package in R and run rcpp_hello_world (that I left in the
package), but when I try to run sum2cpp(1:2) I have an error message
contained in a window named “Microsoft Visual C++ Library”:
“This application has requested the Runtime to terminate in an unusual
way. Please contact the application’s support team for more
information.”
And the R GUI freezes, thus forcing me to kill the R GUI process.
What is this Visual C++ thing? Some problem with finding a tool? My
path is PATH=C:\R\Rtools\bin;C:\R\Rtools\gcc-4.6.3\bin;C:\R\R-2.15.1\bin;
Some problem with wrong writing of the .h, .cpp or .R files? This is
the first time that I create a package, so I may have made beginner’s
mistakes...
If you need any other information, just ask me.
Regards,
Valentin
More information about the Rcpp-devel
mailing list