[Rcpp-devel] Question regarding integrating preexisting C++ code via Rcpp

Simon Fuller simonfuller9 at gmail.com
Tue Oct 11 21:14:30 CEST 2011


Hello,

My apologies for not posting comprehensive code. My intention was only to
lessen the reading burden for you.

However I must aver, despite your concerns to the contrary, taht you have
already been very helpful. I have taken your advice on board, in particular
concerning include order. I have hence managed, with a bit of trouble, to
push through a few groups of errors.

I am currently getting this error:

/home/simon/College/PackageOne/src/BZip/BinaryTree.h: In function ‘SEXPREC*
file354d98a8(SEXPREC*, SEXPREC*)’:
/home/simon/College/PackageOne/src/BZip/BinaryTree.h:8:1: error: expected
primary-expression before ‘template’
/home/simon/College/PackageOne/src/BZip/BinaryTree.h:8:1: error: expected
‘;’ before ‘template’


Apparently "expected primary-expression before ‘template’" gets flagged when
a template is declared within a function. I am guessing that this might be
due to using inline, which might wrap the code in a function?

I was getting similar errors for a Suffix Tree class, i.e.

/SuffixTree.h:47:29: error: local class ‘class file7e587564(SEXPREC*,
SEXPREC*)::SuffixTree’ shall not have static data member
‘file7e587564(SEXPREC*, SEXPREC*)::Edge file7e587564(SEXPREC*,
SEXPREC*)::SuffixTree::Edges [219001]’

This error ('local class shall not have static data member') is evidently
flagged when a local class, i.e. one declared within a function, illegally
holds a static variable.

I used a quick workaround, with a bump in big-O, with the above. Similarly
here, I can specialize my template reasonably quickly - it is not too big a
template.

But am I right that these errors are due to inline, in your opinion? The
clear similarity is that both the class with the static variable, and the
template class, are flagging errors that pertain to them being declared
within a function.

 I think I can see a quick solution, (not to use the template - I don''t
need genericity here anyway,) but I would not mind to get my Suffix Tree
back in the short term, so if you reckon that the error is inline-specific,
I would be keen to fire ahead and make a package or use modules (which ever
would be safest, i.e. most foolproof) sooner rather than later.

Thanks again,

Simon















On Tue, Oct 11, 2011 at 3:07 PM, Dirk Eddelbuettel <edd at debian.org> wrote:

>
> On 11 October 2011 at 10:53, Simon Fuller wrote:
> | To be safe, I wrote a couple of quick codes that use the relevant
> includes, and
> | these work fine when using g++ from the terminal, so I do not think that
> it is
> | my c++ sources as such that are causing the problem, as far as I can
> ascertain
> | myself.
>
> Use cxxfunction(...., verbose=TRUE) and study the generated file as well as
> environment variable (eg R CMD ... arguments) used.  Copy and paste these
> arguments into a shell script to make repeated calling easier.  Then modify
> the source to test suspected fixes.
>
> Unfortunately, include order can matter greatly. And cxxfunction() has
> hooks
> (via plugins) to include at different locations.
>
> We cannot help you __on-list__ unless you post replicable code.
>
> | Thanks again for all your help.
>
> Pleasure, but as I said, you make it pretty hard to let us help you.
>
> Dirk
>
> --
> "Outside of a dog, a book is a man's best friend. Inside of a dog, it is
> too
> dark to read." -- Groucho Marx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20111011/7b1c2267/attachment.htm>


More information about the Rcpp-devel mailing list