[Rd] LENGTH function causing name conflict

Dirk Eddelbuettel edd at debian.org
Fri Sep 27 23:25:50 CEST 2013


On 26 September 2013 at 21:13, Ron Goldman wrote:
| I am attempting to bring R-3.0.2 functionality into a project with a very
| large C++ codebase.  The existing codebase already has a LENGTH function
| defined.  R also defines a LENGTH function.
| 
| I first compiled R as a shared library and linked it into this existing
| codebase, along with RInside. When I run a parseEvalQ with a linear model
| command it will stack dump.  Looking at the backtrace, what is happening is
| that line 51 of lm.c is executing:
| 
| if(n) ny = LENGTH(y)/n;  /* n x ny, or a vector */
| 
| However, the LENGTH call is getting routed into our internal codebase.
|  This causes a stack dump.
| 
| I then tried compiling R as a static library.  After that I couldn't even
| compile my existing code because it flags the issue right off the bat:
| 
| ... error: declaration of C function 'int LENGTH(const ... *)' conflicts
| with
| ... /r/lib64/R/include/Rinternals.h:435: error: previous declaration 'int
| LENGTH(SEXPREC*)' here
| 
| It is not possible to remove/rename the LENGTH function from the existing
| codebase.  Any help would be appreciated in resolving this.

This got discussed a number of times over the years over on the rcpp-devel
list.  The common fixes are


 i)  make sure you define R_NO_REMAP (as our headers do). The Fine Manual says:

	  This remapping can cause problems(1), and can be eliminated by
        defining `R_NO_REMAP' and prepending `Rf_' to _all_ the function names
        used from `Rinternals.h' and `R_ext/Error.h'.

 ii) reordering of headers may help

In sum, and quoting from RcppCommon.h

// include R headers, but set R_NO_REMAP and access everything via Rf_ prefixes
#define R_NO_REMAP
#include <R.h>


Hth, Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com



More information about the R-devel mailing list