[Rcpp-devel] symbols "major" and "minor" under C++11

Jack Wasey jack at jackwasey.com
Tue Mar 10 02:40:16 CET 2015


Dear All,

I followed your interesting and detailed discussion about the problem in
Rcpp 0.11.3 which resulted in compilation failure with "major", "minor"
or "makedev" as function arguments due to leakage from system headers on
Linux.
https://github.com/RcppCore/Rcpp/issues/227

I am posting follow-up here because I'm not sure if this is a valid bug,
but I am seeing the same problem when compiling with clang 3.7 and gcc
4.9.1 on 64 bit ubuntu 14.10 using C++11.

Simply writing the function which demonstrated #227 isn't enough:
cppFunction("int foo(int major) { return(2*major); }")
does compile with the addition of -std=c++11

However, if I create an Rcpp.package.skeleton with attributes and the
example code, and simply add function argument "CharacterVector major"
to the hello world function:

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
List rcpp_hello_world(CharacterVector major) {

    CharacterVector x = CharacterVector::create( "foo", "bar" )  ;
    NumericVector y   = NumericVector::create( 0.0, 1.0 ) ;
    List z            = List::create( x, y ) ;

    return z ;
}

then the RcppExports.cpp doesn't compile. Here is the clang compiler error:

clang++ -I/usr/share/R/include -DNDEBUG
-I"/usr/local/lib/R/site-library/Rcpp/include"  -std=c++11 -fpic  -g -O2
-fstack-protector-strong -Wformat -Werror=format-security
-D_FORTIFY_SOURCE=2 -g  -c RcppExports.cpp -o RcppExports.o
RcppExports.cpp:15:44: error: use of undeclared identifier 'major'
    __result = Rcpp::wrap(rcpp_hello_world(major));

Here is the code from RcppExports.cpp:
#include <Rcpp.h>

using namespace Rcpp;

// rcpp_hello_world
List rcpp_hello_world(CharacterVector major);
RcppExport SEXP majmin11_rcpp_hello_world(SEXP majorSEXP) {
BEGIN_RCPP
    Rcpp::RObject __result;
    Rcpp::RNGScope __rngScope;
    Rcpp::traits::input_parameter< CharacterVector >::type major(majorSEXP);
    __result = Rcpp::wrap(rcpp_hello_world(major));
    return __result;
END_RCPP
}

As it seems to arise from RcppExports, I hope you agree that using
Rcpp.package.skeleton and making a small change constitutes an
appropriate minimal example, since I couldn't reproduce with one single
snippet.

I may well be doing something wrong, but it does seem again like the
system symbols leaking through, since renaming from "major" to "mjr"
fixes the problem (as does removing C++11 compiler flag). I did look at
the merged solution to #227, but honestly it's beyond me to attempt to
dig any deeper.

I realize this is quite a specific and exasperating problem. If you
think it's a bug, I could comment on #227 or open a new issue.

Thanks,
Jack


More information about the Rcpp-devel mailing list