[Rcpp-devel] Compilation error

Romain François francoisromain at free.fr
Thu Jan 7 13:32:44 CET 2010


Hello,

An easy way to fill the gaps is to take advantage of the so-called 
inline trick, see for example : 
http://dirk.eddelbuettel.com/blog/2009/12/20/#rcpp_inline_example

require( inline )
require( Rcpp )

f <- cfunction(
	signature(nvec="double", ivec="integer", svec="character", nmat="double"),
	'
	SEXP rl=R_NilValue;
	RcppVector<double> nv(nvec);
	RcppVector<int> iv(ivec);
	RcppStringVector sv(svec);
	RcppMatrix<double> nm(nmat);
	return rl;',
	Rcpp = TRUE, verbose = TRUE )

f( rnorm(10), 1:10, letters, matrix(rnorm(20), nc = 4) )


On my system this gives this :

Setting PKG_CXXFLAGS to -I/usr/local/lib/R/library/Rcpp/lib -std=c++0x 

Setting PKG_LIBS to -L/usr/local/lib/R/library/Rcpp/lib -lRcpp 
-Wl,-rpath,/usr/local/lib/R/library/Rcpp/lib
Compilation argument:
  /usr/local/lib/R/bin/R CMD SHLIB file327b23c6.cpp
g++ -I/usr/local/lib/R/include  -I/usr/local/include 
-I/usr/local/lib/R/library/Rcpp/lib -std=c++0x -fpic  -g -O2 -c 
file327b23c6.cpp -o file327b23c6.o
g++ -shared -L/usr/local/lib -o file327b23c6.so file327b23c6.o 
-L/usr/local/lib/R/library/Rcpp/lib -lRcpp 
-Wl,-rpath,/usr/local/lib/R/library/Rcpp/lib -L/usr/local/lib/R/lib -lR
Program source:
   1: #include <Rcpp.h>
   2:
   3:
   4: extern "C" {
   5:   SEXP file327b23c6 ( SEXP nvec, SEXP ivec, SEXP svec, SEXP nmat );
   6: }
   7:
   8: SEXP file327b23c6 ( SEXP nvec, SEXP ivec, SEXP svec, SEXP nmat ) {
   9:
  10: SEXP rl=R_NilValue;
  11: RcppVector<double> nv(nvec);
  12: RcppVector<int> iv(ivec);
  13: RcppStringVector sv(svec);
  14: RcppMatrix<double> nm(nmat);
  15: return rl;
  16:   Rf_warning("your C program does not return anything!");
  17:   return R_NilValue;
  18: }
 >
 > f( rnorm(10), 1:10, letters, matrix(rnorm(20), nc = 4) )
NULL

which tells me you need to set the PKG_CXXFLAGS and PKG_LIBS environment 
variables.

Hope this helps

Romain


On 01/07/2010 01:20 PM, Mattias Nyström wrote:
> Hello,
>
> 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
>
> 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()'
>
>
>
> _______________________________________________
> 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


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009
|- http://tr.im/IW9B : C++ exceptions at the R level
`- http://tr.im/IlMh : CPP package: exposing C++ objects



More information about the Rcpp-devel mailing list