Skip to content

[Rcpp-devel] Templates failing to specialize

3 messages · Ian Fellows, Davor Cubranic

#
Hi,

I have am having trouble using template classes in rcpp. The compiling process works just fine, but there are errors on link. It seems as if the methods are not getting specialized.

The Error:
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/Library/Frameworks/R.framework/Versions/2.13/Resources/library/gergm/libs/x86_64/gergm.so':
  dlopen(/Library/Frameworks/R.framework/Versions/2.13/Resources/library/gergm/libs/x86_64/gergm.so, 6): Symbol not found: __ZN5gergm9BinaryNetINS_14DirectedVertexEE4sizeEv
  Referenced from: /Library/Frameworks/R.framework/Versions/2.13/Resources/library/gergm/libs/x86_64/gergm.so
  Expected in: flat namespace
 in /Library/Frameworks/R.framework/Versions/2.13/Resources/library/gergm/libs/x86_64/gergm.so
Error: loading failed
Execution halted
ERROR: loading failed


The basic form of the class is:

template<class T>
class BinaryNet{
public:
	int size();
};

template<class T>
void BinaryNet<T>::size(){return 1;}

BinaryNet is called in a function in a separate c++ file. If I explicitly add the specialization, then everything works out fine

template<>
void BinaryNet<DirectedVertex>::size(){return 1;}

How can I make sure that these specializations are created. I apologize if this is more a c++ question than an Rcpp one.


Best,
Ian


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110627/1c187994/attachment.htm>
#
See the C++ FAQ: http://www.parashift.com/c++-faq-lite/templates.html#faq-35.13

Davor
On 2011-06-27, at 8:49 AM, Ian Fellows wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110627/2733edc4/attachment.htm>
#
Okay, so at the risk of asking another stupid question...


I'm a bit unclear about how to write the R constructor for a class being exported via the module facility.


class Foo{
	public:
		int i;
		Foo();
		Foo(SEXP);
}



int test(Foo f){
	return f.i;
}

RCPP_MODULE(amodule){
	using namespace Rcpp ;
	function("test",&test);
	class<Foo>("Foo");
}


I assume that I need to write Foo(SEXP) in such a way that the external pointer is extracted, and then 'i' is copied over. How does one do this?


Thanks for the help,
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110627/93ed818c/attachment.htm>