[Rcpp-devel] Compilation error
Dirk Eddelbuettel
edd at debian.org
Thu Jan 7 14:37:32 CET 2010
Matthias,
On 7 January 2010 at 13:20, Mattias Nyström wrote:
| I've just started with Rcpp. When I compile my file mattias.cpp, using: "R CMD SHLIB mattias.cpp", I get the error below. The source code of the file mattias.cpp is also written below. What can the problem be?
|
| Source code of mattias.cpp:
| #include <Rcpp.h>
| SEXP firstfunction(SEXP nvec, SEXP ivec, SEXP svec, SEXP nmat)
| {
| SEXP rl=R_NilValue;
| RcppVector<double> nv(nvec);
| RcppVector<int> iv(ivec);
| RcppStringVector sv(svec);
| RcppMatrix<double> nm(nmat);
|
| return rl;
| }
|
| The compilation error:
| g++ -I"C:/PROGRA~1/R/R-210~1.0/include" -O2 -Wall -c mattias.cpp -o mattias.o
| mattias.cpp: In function 'SEXPREC* firstfunction(SEXPREC*, SEXPREC*, SEXPREC*, SEXPREC*)':
| mattias.cpp:9: warning: control reaches end of non-void function
That is weird. I think you need a 'RcppExport SEXP firstfunction ...' as
RcppExport is a cheap way to get the 'export "C"' here that makes this behave
when called from C - as R does).
Other than that step 1 (compilation) looks good. It find the headers. Which
is strange as you didn't say where there. Is mattias.cpp per chance in the
same directory as the headers and you are in that too? You may want to
change that as well.
| g++ -shared -s -o mattias.dll tmp.def mattias.o -LC:/PROGRA~1/R/R-210~1.0/bin -lR
| mattias.o:mattias.cpp:(.text+0xc0): undefined reference to `RcppVector<double>::RcppVector(SEXPREC*)'
| mattias.o:mattias.cpp:(.text+0xd2): undefined reference to `RcppVector<int>::RcppVector(SEXPREC*)'
| mattias.o:mattias.cpp:(.text+0xe4): undefined reference to `RcppStringVector::RcppStringVector(SEXPREC*)'
| mattias.o:mattias.cpp:(.text+0xfd): undefined reference to `RcppMatrix<double>::RcppMatrix(SEXPREC*)'
| mattias.o:mattias.cpp:(.text+0x10f): undefined reference to `RcppStringVector::~RcppStringVector()'
| mattias.o:mattias.cpp:(.text+0x142): undefined reference to `RcppStringVector::~RcppStringVector()'
You will get use to errors like this. 'Undefined reference' simply means that
you have references to code objects you did not provide in the linking stage
as there is no -lRcpp here.
And as Romain kindly pointed while I was still sleeping (don't you love
friends in different timezones?) you can automate this using inlines.
Besides that the use of Rcpp:::CxxFlags() and Rcpp:::LdFlags() is explained
eg in the Rcpp-package manual page and other places such as the webpage. You
can use these to get the value you need to pass to PKG_LIBS and possibly
PKG_CPPFLAGS (if you need a -I switch)
Dirk
--
Three out of two people have difficulties with fractions.
More information about the Rcpp-devel
mailing list