[Rcpp-devel] Compilation error
Mattias Nyström
Mattias.Nystrom at srh.slu.se
Fri Jan 8 11:20:17 CET 2010
Thanks for your replies Dirk and Romain. My problem was the flags. I tried both setting them in "Makefile.win" with "Rcpp:::CxxFlags()" and "Rcpp:::LdFlags()" and create Environmental variables in Windows, and both works fine :) Thanks!
And as you pointed out Dirk, I didn't use RcppExport, so that was a problem too. I saw that Romain used "extern "C"". Thanks for your explanations about that. I had not understood how R did the call to C before.
//Mattias
-----Original Message-----
From: rcpp-devel-bounces at r-forge.wu-wien.ac.at [mailto:rcpp-devel-bounces at r-forge.wu-wien.ac.at] On Behalf Of Dirk Eddelbuettel
Sent: den 7 januari 2010 14:38
To: Mattias Nyström
Cc: rcpp-devel at lists.r-forge.r-project.org
Subject: Re: [Rcpp-devel] Compilation error
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.
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel at lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
More information about the Rcpp-devel
mailing list