[Rcpp-devel] dyn.load error - symbol not found - expected in: flat namespace

Lescai, Francesco f.lescai at ucl.ac.uk
Fri Jul 6 16:50:39 CEST 2012


Argh.. Apologies guys.. Found the error myself.
Constructor and deconstructor must be specified with {} even if no code is foreseen for them.

A novice error, hope at least highlighting it could be useful to other newbies like me :-)

cheers,
Francesco


On 6 Jul 2012, at 15:37, Lescai, Francesco wrote:

> Hi there,
> I've seen other posts similar to this one, but I'm a complete novice in the use of Rcpp and couldn't really figure out how to solve the issue.
> 
> I'm learning how to use Rcpp before connecting R to some C++ classes I'm developing.
> I started with a simple home made example, but in both cases compiling .cpp and header files or compiling inline code, I get the same outcome error "unable to load shared object" and then "Symbol not found" with some characters before and after my class name.
> 
> I've seen Mac OS might have some issues, therefore I tested it also on an Ubuntu virtual machine, but the result is the same error message.
> Also, I'm using an R-devel version here but I'm having the same problem with R 14 as well.
> I'll copy below all the relevant information (bit lengthy, I'm sorry).
> 
> I'd really appreciate some help here to point me in the right direction.
> thanks very much,
> Francesco
> 
> 
> ------case 1 - external files -------------------
> 
> PKG_CPPFLAGS=`Rscript -e 'Rcpp:::CxxFlags()'` PKG_LIBS=`Rscript -e 'Rcpp:::LdFlags()'` R CMD SHLIB example.cpp 
> g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG -I/Library/Frameworks/R.framework/Versions/2.16/Resources/library/Rcpp/include -I/usr/local/include    -fPIC  -g -O2  -c example.cpp -o example.o
> g++ -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o example.so example.o /Library/Frameworks/R.framework/Versions/2.16/Resources/library/Rcpp/lib/x86_64/libRcpp.a -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
> 
>> library(Rcpp)
>> library(inline)
>> dyn.load("example.so")
> Error in dyn.load("example.so") : 
>  unable to load shared object '/Users/rehbfle/Documents/CPPexercise/RCPP/example.so':
>  dlopen(/Users/rehbfle/Documents/CPPexercise/RCPP/example.so, 6): Symbol not found: __ZN7exampleD1Ev
>  Referenced from: /Users/rehbfle/Documents/CPPexercise/RCPP/example.so
>  Expected in: flat namespace
> in /Users/rehbfle/Documents/CPPexercise/RCPP/example.so
> 
> 
> ---------case 2 - inline code-----------------------------------------
> 
> fx<-cxxfunction(signature(), plugin="Rcpp", include=inc) 
> Error in dyn.load(libLFile) : 
>  unable to load shared object '/var/folders/qj/p9_mz7r9661gynb8w88sfbvhy6s5_l/T//RtmpaMinm3/file34b510aaf8e3.so':
>  dlopen(/var/folders/qj/p9_mz7r9661gynb8w88sfbvhy6s5_l/T//RtmpaMinm3/file34b510aaf8e3.so, 6): Symbol not found: __ZN7exampleC1Eii
>  Referenced from: /var/folders/qj/p9_mz7r9661gynb8w88sfbvhy6s5_l/T//RtmpaMinm3/file34b510aaf8e3.so
>  Expected in: flat namespace
> in /var/folders/qj/p9_mz7r9661gynb8w88sfbvhy6s5_l/T//RtmpaMinm3/file34b510aaf8e3.so
> 
> 
> Below the code details:
> 
> example.h
> -------------------------
> #ifndef EXAMPLE_H
> #define EXAMPLE_H
> 
> class example
> {
> 
> 	private:
> 			float resultone;
> 			int resultwo;
>    public:
>            example(int x, int y);
>            ~example();
>            float multiply(int x, int y);
>            int doublex(int x);
> 
> };      
> 
> 
> #endif
> 
> 
> example.cpp
> ---------------------------
> #include "example.h"
> #include <Rcpp.h>
> 
> using namespace Rcpp;
> 
> example::example(int x, int y){}
> 
> float example::multiply(int x, int y){
>        resultone = x * y;
>        return resultone;
> }
> 
> int example::doublex(int x){
>        resultwo = x * 2;
>        return resultwo;
> }
> 
> RCPP_MODULE(prova){
> 
>        	class_<example>("example")
>        	.constructor<int,int>()
>        	.method("square", &example::multiply)
>        	.method("doppio", &example::doublex)
>        	;
> }
> 
> 
> ----------inline code----------------
> inc <-'using namespace Rcpp;
> class example
> {
> 		private:
> 			float resultone;
> 			int resultwo;
> 			
>        public:
>                example(int x, int y);
>                ~example();
>                float multiply(int x, int y){
>                	resultone = x * y;
>                	return resultone;
>                }
>                int doublex(int x){
>                	resultwo = x * 2;
>                	return resultwo;
>                }
> 			
> };    
> 
> RCPP_MODULE(prova){
> 
>        	class_<example>("example")
>        	.constructor<int,int>()
>        	.method("square", &example::multiply)
>        	.method("doppio", &example::doublex)
>        	;
>        }'
> 
> 
> -----------------
>> sessionInfo()
> R Under development (unstable) (2012-07-02 r59715)
> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
> 
> locale:
> [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base     
> 
> other attached packages:
> [1] inline_0.3.8 Rcpp_0.9.13 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> 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