Hello Darren,<br><br>Thank you for your advice. It makes good sense.<br><br>I now have a linker problem, and I have written some code to abstract the problem for your viewing.<br><br>The error message is:<br>"Error in dyn.load(libLFile) : <br>
unable to load shared object '/tmp/RtmpBFr1mw/file44b636b6.so':<br> /tmp/RtmpBFr1mw/file44b636b6.so: undefined symbol: _Z6sumvecSt6vectorIiSaIiEE"<br><br>It seems safe to say that it cannot find the cpp file for LinkTest.h<br>
<br>The problem might be with how to use the"includes" argument for cxxfunction (see 1.b below).<br><br>It seems a common enough problem, but I have not been able to gain a clearer understanding by reading past comments on it, as most of these seem to pertain to packages. So I will post the relevant code here, and the full output from verbose=TRUE below it:<br>
<br>1. R Calling Function<br>linktest<-cxxfunction( signature( vec = "numeric", len = "integer" ), paste( readLines( "/home/simon/College/PackageOne/src/BZip/LinkTestWrap.cpp"),collapse = "\n" ) , plugin = "Rcpp",verbose=TRUE )<br>
<br>1.b I also tried using user includes in the cxxfunction, and taking them out of the cpp file. But they don't seem to be parse properly in the created code, i.e.:<br>"// user includes<br> /home/simon/College/PackageOne/src/BZip/LinkTest.h"<br>
which the compiler naturally flags.<br><br><br>2. LinkTestWrap.cpp: Rcpp Wrapping Function (for use by inline)<br>#include <Rcpp.h><br>#include <vector><br>#include "/home/simon/College/PackageOne/src/BZip/LinkTest.h"<br>
<br> using std::vector;<br><br> vector<int> input_vector( as< vector<int> >( vec ) );<br> int length = as<int> ( len );<br><br> int res = sumvec( input_vector );<br><br> return Rcpp::wrap( res );<br>
<br>3. LinkTest.h<br>#include <vector><br>int sumvec(std::vector<int> vec);<br><br>4.LinkTest.cpp<br>#include "/home/simon/College/PackageOne/src/BZip/LinkTest.h"<br><br>using std::vector;<br><br>int sumvec(vector<int> vec){<br>
int total = 0;<br> for( vector<int>::const_iterator it = vec.begin(); it != vec.end(); ++it ){<br> total += *it;<br> }<br> return total;<br>}<br><br>Thanks again,<br><br>Simon<br><br><br><br>I thought the problem is with inline though. To take the link you gave:<br>
<a href="http://stackoverflow.com/questions/3221422/gcc-template-error" target="_blank">http://stackoverflow.com/questions/3221422/gcc-template-error</a><br>
One answer cites: "The errors that you have posted suggest that the problem is within the function <code>void init_module_PyCML()</code>. It would therefore appear that you have tried to define a function template within the body of another function." I interpreted this to be due to inline because the problem with static member variables certainly seems to be because the class and other code is defined within a wrapper function by inline.<br>
<br><div class="gmail_quote">On Wed, Oct 12, 2011 at 12:24 AM, Darren Cook <span dir="ltr"><<a href="mailto:darren@dcook.org" target="_blank">darren@dcook.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>> My apologies for not posting comprehensive code. My intention was only to<br>
> lessen the reading burden for you.<br>
<br>
</div>Don't post comprehensive code :-)<br>
But if you can discover the smallest possible example that shows the<br>
problem, that will encourage lots of helpful responses.<br>
<div><br>
<br>
> I am currently getting this error:<br>
><br>
> /home/simon/College/PackageOne/src/BZip/BinaryTree.h: In function ‘SEXPREC*<br>
> file354d98a8(SEXPREC*, SEXPREC*)’:<br>
> /home/simon/College/PackageOne/src/BZip/BinaryTree.h:8:1: error: expected<br>
> primary-expression before ‘template’<br>
> /home/simon/College/PackageOne/src/BZip/BinaryTree.h:8:1: error: expected<br>
> ‘;’ before ‘template’<br>
<br>
<br>
</div>This is saying that you've not finished a statement before defining<br>
another one. E.g. see<br>
<a href="http://stackoverflow.com/questions/3221422/gcc-template-error" target="_blank">http://stackoverflow.com/questions/3221422/gcc-template-error</a><br>
<br>
It could mean a missing semi-colon in the file being included before<br>
this one. If there are no statements or #include lines before line 8 in<br>
BinaryTree.h, look at the files that include BinaryTree.h.<br>
<div><br>
> I think I can see a quick solution, (not to use the template - I don''t<br>
</div>> need genericity here anyway,)...<br>
<br>
If that is true, then the Smallest Possible Example would be very<br>
interesting to the Rcpp developers, I'm sure.<br>
<br>
Darren<br>
<font color="#888888"><br>
<br>
--<br>
Darren Cook, Software Researcher/Developer<br>
<br>
<a href="http://dcook.org/work/" target="_blank">http://dcook.org/work/</a> (About me and my work)<br>
<a href="http://dcook.org/blogs.html" target="_blank">http://dcook.org/blogs.html</a> (My blogs and articles)<br>
</font><div><div></div><div>_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></div></div></blockquote></div><br>