[Rcpp-devel] Package Development with Rcpp, RcppArmadillo, BH and bigmemory for systems without full C++ extensions
Dirk Eddelbuettel
edd at debian.org
Wed Jul 30 04:50:06 CEST 2014
Hi Scott,
On 30 July 2014 at 11:53, Scott Ritchie wrote:
| I've been developing an Rcpp/RcppArmadillo package that makes use of BigMatrix
| objects from the bigmemory package, and I've had a series of confusing
| encounters with C++11, so I want to check that I'm doing the right thing.
|
| Before using RcppArmadillo, I had enabled C++11 extensions by including
| SystemRequires: C++11 in my DESCRIPTION file, in order to turn off compiler
| warnings due to the BigMatrix class's use of boost headers.
That is one of several ways to turn it on.
I prefer to use src/Makevars{,win} with a setting of
CXX_STD = CXX11
as there may be other things to toggle in src/Makevars{,.win} (see below),
and to me it is more logical to keep the setting (C++11) along with the files
(in src/) -- but at the end of the day either way works.
| Now that I've added RcppArmadillo, I've had to use custom Makevars and
| Makevars.win files to correctly link the package to LAPACK libraries if they're
| installed. I've generated these files using RcppArmadillo.package.skeleton().
|
| Now when I try to install my package on a different system (Ubuntu 12.04), I
| get the following warnings from files which include the RcppArmadillo.h header
| file:
|
|
| WARNING: your C++ compiler is in C++11 mode, but it has incomplete support
| for C++11 features; if something breaks, you get to keep all the pieces
|
|
| This is because the g++ compiler is version 4.6.3, so it only has limited
| support for C++11 extensions (-std=c++0x).
Correct. Ubuntu 12.04 is old.
If you can, upgrade to 14.04.
If you can't, suffer the consequences such as an old compiler. [ You could
also get a new g++ from another PPA, but I'd just upgrade. But maybe you
can't. ]
| Since I haven't written any code that makes use of C++11 extensions, I have
| tried turning them off in my RcppArmadillo files by adding #define
| ARMA_DONT_USE_CXX11 before the include statement #include <RcppArmadillo.h>.
| However, this does not get added to RcppExports.cpp so I still get the compiler
| warning once when I install the package.
If you do not use C++11, there may be another option -- provided you do not
plan to upload to CRAN. CRAN is very black and white: C++ is either done by
the old 1998 standard, or the 2011 standard.
You can get 'long long' as I recall with intermediate value.
Here is Section 2.2 of the g++ documentation:
2.2 C++ language
================
GCC supports the original ISO C++ standard (1998) and contains
experimental support for the second ISO C++ standard (2011).
The original ISO C++ standard was published as the ISO standard
(ISO/IEC 14882:1998) and amended by a Technical Corrigenda published in
2003 (ISO/IEC 14882:2003). These standards are referred to as C++98 and
C++03, respectively. GCC implements the majority of C++98 ('export' is
a notable exception) and most of the changes in C++03. To select this
standard in GCC, use one of the options '-ansi', '-std=c++98', or
'-std=c++03'; to obtain all the diagnostics required by the standard,
you should also specify '-pedantic' (or '-pedantic-errors' if you want
them to be errors rather than warnings).
A revised ISO C++ standard was published in 2011 as ISO/IEC 14882:2011,
and is referred to as C++11; before its publication it was commonly
referred to as C++0x. C++11 contains several changes to the C++
language, most of which have been implemented in an experimental C++11
mode in GCC. For information regarding the C++11 features available in
the experimental C++11 mode, see
<http://gcc.gnu.org/projects/cxx0x.html>. To select this standard in
GCC, use the option '-std=c++11'; to obtain all the diagnostics required
by the standard, you should also specify '-pedantic' (or
'-pedantic-errors' if you want them to be errors rather than warnings).
More information about the C++ standards is available on the ISO C++
committee's web site at <http://www.open-std.org/jtc1/sc22/wg21/>.
By default, GCC provides some extensions to the C++ language; *Note
Options Controlling C++ Dialect: C++ Dialect Options. Use of the '-std'
option listed above will disable these extensions. You may also select
an extended version of the C++ language explicitly with '-std=gnu++98'
(for C++98 with GNU extensions) or '-std=gnu++11' (for C++11 with GNU
extensions). The default, if no C++ language dialect options are given,
is '-std=gnu++98'.
So if you are aiming for local / in-house use, then
PKG_CXXFLAGS=-std=c++03
may be all you need. It's been a while since I tried as I keep most of my
packages in a 'ready for CRAN' mode, and tend to keep those local to work in
a similar shape.
| I've additionally removed SystemRequirements: C++11 from my DESCRIPTION file
| but that seems to make no difference (my Rcpp code that doesnt use the
| armadillo headers still compiles without warnings, despite including the BH
| dependency.
Well everything builds. It is just a warning, or set of warnings.
| I'm not sure how much of an issue this is, because none of my code seems to be
| broken when I install on the system without full C++11 extension support. Can I
| just ignore this warning, and is what I have done correct?
Yes of course. Lots of packages install with a ton of warnings when you
default "-Wall -pedantic" as I do. I think RJSONIO is just one example that I
upgraded in the last few days.
Warnings != Errors but it is still best to not have any as they may mask errors.
Dirk
| My package versions on both systems are:
|
| Rcpp_0.11.2
| RcppArmadillo_0.4.320.0
|
|
| Kind Regards,
|
| Scott Ritchie
|
|
|
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
More information about the Rcpp-devel
mailing list