Skip to content

[Rcpp-devel] multiple definition problem

2 messages · Steve Jaffe, Romain Francois

#
On 24 Aug 2013 at 09:04, romain at r-enthusiasts.com wrote:
Another alternative is simply to declare such a function as "inline." 

This does not mean that it will be physically inlined -- it may or may not
be, at the discretion of the compiler; it only means that the compiler/linker
are responsible for eliminating multiple definitions, ie it simply makes it 
legal for the function to be defined in multiple compilation units, "as if" it 
were inline.

Include guards won't prevent multiple definition errors when the same header 
is included by multiple compilation units. Any function defined in a header file, 
which is not in a class definition, and is not a template, should be 
declared as inline.

Steve Jaffe
steve_jaffe at yahoo.com
#
Le 29/08/13 18:59, Steve Jaffe a ?crit :
I don't think that works and I've had examples to verify this belief.

Quite recently, implementations of wrap and as for sparse matrices 
classes in RcppArmadillo were huge and yet declared as inline. And we 
still had the multiple definitions problem. There were other issues with 
them, but that's beyond the scope of this thread and this has been fixed 
anyway.
Sure. This was not the problem, but it was a bit scary to see a header 
file without include guards.
If this were true we just would have to declare everything as inline.

I don't mean to create a debate here, but I don't think just using the 
inline keyword would have fixed this issue.

Romain