Skip to content

Arma version selection: Package without deprecation notes ready for C++14 or later #476

@eddelbuettel

Description

@eddelbuettel

As an example of a simple package that

  • neither depends on or enforces C++11 but simply uses the newest C++ standard available
  • does not trigger any deprecation warnings

we show the (not yet on CRAN but recent) example package rcppmlpackexamples of using mlpack via its C++ API directly from an R package. It also works the exact same way in CRAN packages RcppDE as well as for several local packages of mine not on CRAN such as RcppKalman or winsorize (details not shown here).

Example of default compilation before any changes: falls back to 14.6.3 with warning

edd@paul:~/git/rcppmlpack-examples(master)$ install.r
* installing *source* package found in current working directory ...
* installing *source* package ‘rcppmlpackexamples’ ...
** this is package ‘rcppmlpackexamples’ version ‘0.0.1’
** using staged installation
** libs
using C++ compiler: ‘g++ (Ubuntu 14.2.0-19ubuntu2) 14.2.0’
ccache g++ -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include' -I'/usr/local/lib/R/site-library/mlpack/include'    -fopenmp -fpic  -O3 -Wall -pipe -pedantic -Wno-parentheses -Wno-ignored-attributes -Wno-unused-function    -c RcppExports.cpp -o RcppExports.o
ccache g++ -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include' -I'/usr/local/lib/R/site-library/mlpack/include'    -fopenmp -fpic  -O3 -Wall -pipe -pedantic -Wno-parentheses -Wno-ignored-attributes -Wno-unused-function    -c kMeans.cpp -o kMeans.o
ccache g++ -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include' -I'/usr/local/lib/R/site-library/mlpack/include'    -fopenmp -fpic  -O3 -Wall -pipe -pedantic -Wno-parentheses -Wno-ignored-attributes -Wno-unused-function    -c linearRegression.cpp -o linearRegression.o
ccache g++ -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include' -I'/usr/local/lib/R/site-library/mlpack/include'    -fopenmp -fpic  -O3 -Wall -pipe -pedantic -Wno-parentheses -Wno-ignored-attributes -Wno-unused-function    -c loadDefaultPrediction.cpp -o loadDefaultPrediction.o
ccache g++ -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include' -I'/usr/local/lib/R/site-library/mlpack/include'    -fopenmp -fpic  -O3 -Wall -pipe -pedantic -Wno-parentheses -Wno-ignored-attributes -Wno-unused-function    -c randomForest.cpp -o randomForest.o
In file included from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h:29,
                 from RcppExports.cpp:4:
/usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo/version/arma.h:71:153: note: ‘#pragma message: Using fallback compilation with Armadillo 14.6.3. Please consider defining -DARMA_USE_CURRENT. See GitHub issue #475 for more.’
   71 |         #pragma message("Using fallback compilation with Armadillo 14.6.3. Please consider defining -DARMA_USE_CURRENT. See GitHub issue #475 for more.")
      |                                                                                                                                                         ^
In file included from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h:29,
                 from rcppmlpackexamples.h:18,
                 from kMeans.cpp:2:
/usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo/version/arma.h:71:153: note: ‘#pragma message: Using fallback compilation with Armadillo 14.6.3. Please consider defining -DARMA_USE_CURRENT. See GitHub issue #475 for more.’
   71 |         #pragma message("Using fallback compilation with Armadillo 14.6.3. Please consider defining -DARMA_USE_CURRENT. See GitHub issue #475 for more.")
      |                                                                                                                                                         ^
In file included from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h:29,
                 from rcppmlpackexamples.h:18,
                 from linearRegression.cpp:2:
/usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo/version/arma.h:71:153: note: ‘#pragma message: Using fallback compilation with Armadillo 14.6.3. Please consider defining -DARMA_USE_CURRENT. See GitHub issue #475 for more.’
   71 |         #pragma message("Using fallback compilation with Armadillo 14.6.3. Please consider defining -DARMA_USE_CURRENT. See GitHub issue #475 for more.")
      |                                                                                                                                                         ^
In file included from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h:29,
                 from rcppmlpackexamples.h:18,
                 from randomForest.cpp:2:
/usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo/version/arma.h:71:153: note: ‘#pragma message: Using fallback compilation with Armadillo 14.6.3. Please consider defining -DARMA_USE_CURRENT. See GitHub issue #475 for more.’
   71 |         #pragma message("Using fallback compilation with Armadillo 14.6.3. Please consider defining -DARMA_USE_CURRENT. See GitHub issue #475 for more.")
      |                                                                                                                                                         ^
In file included from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h:29,
                 from rcppmlpackexamples.h:18,
                 from loadDefaultPrediction.cpp:2:
/usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo/version/arma.h:71:153: note: ‘#pragma message: Using fallback compilation with Armadillo 14.6.3. Please consider defining -DARMA_USE_CURRENT. See GitHub issue #475 for more.’
   71 |         #pragma message("Using fallback compilation with Armadillo 14.6.3. Please consider defining -DARMA_USE_CURRENT. See GitHub issue #475 for more.")
      |                                                                                                                                                         ^
ccache g++ -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -Wl,-z,relro -o rcppmlpackexamples.so RcppExports.o kMeans.o linearRegression.o loadDefaultPrediction.o randomForest.o -fopenmp -llapack -lblas -lgfortran -lm -lquadmath -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/00LOCK-rcppmlpack-examples/00new/rcppmlpackexamples/libs
** R
** data
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (rcppmlpackexamples)
edd@paul:~/git/rcppmlpack-examples(master)$ 

Example after adding -DARMA_USE_CURRENT in src/Makevars{,.win} to PKG_CXXFLAGS: uses 15.0.1 without warnings

edd@paul:~/git/rcppmlpack-examples(master)$ install.r
* installing *source* package found in current working directory ...
* installing *source* package ‘rcppmlpackexamples’ ...
** this is package ‘rcppmlpackexamples’ version ‘0.0.1’
** using staged installation
** libs
using C++ compiler: ‘g++ (Ubuntu 14.2.0-19ubuntu2) 14.2.0’
ccache g++ -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include' -I'/usr/local/lib/R/site-library/mlpack/include'    -fopenmp -DARMA_USE_CURRENT -fpic  -O3 -Wall -pipe -pedantic -Wno-parentheses -Wno-ignored-attributes -Wno-unused-function    -c RcppExports.cpp -o RcppExports.o
ccache g++ -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include' -I'/usr/local/lib/R/site-library/mlpack/include'    -fopenmp -DARMA_USE_CURRENT -fpic  -O3 -Wall -pipe -pedantic -Wno-parentheses -Wno-ignored-attributes -Wno-unused-function    -c kMeans.cpp -o kMeans.o
ccache g++ -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include' -I'/usr/local/lib/R/site-library/mlpack/include'    -fopenmp -DARMA_USE_CURRENT -fpic  -O3 -Wall -pipe -pedantic -Wno-parentheses -Wno-ignored-attributes -Wno-unused-function    -c linearRegression.cpp -o linearRegression.o
ccache g++ -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include' -I'/usr/local/lib/R/site-library/mlpack/include'    -fopenmp -DARMA_USE_CURRENT -fpic  -O3 -Wall -pipe -pedantic -Wno-parentheses -Wno-ignored-attributes -Wno-unused-function    -c loadDefaultPrediction.cpp -o loadDefaultPrediction.o
ccache g++ -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include' -I'/usr/local/lib/R/site-library/mlpack/include'    -fopenmp -DARMA_USE_CURRENT -fpic  -O3 -Wall -pipe -pedantic -Wno-parentheses -Wno-ignored-attributes -Wno-unused-function    -c randomForest.cpp -o randomForest.o
ccache g++ -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -Wl,-z,relro -o rcppmlpackexamples.so RcppExports.o kMeans.o linearRegression.o loadDefaultPrediction.o randomForest.o -fopenmp -llapack -lblas -lgfortran -lm -lquadmath -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/00LOCK-rcppmlpack-examples/00new/rcppmlpackexamples/libs
** R
** data
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (rcppmlpackexamples)
edd@paul:~/git/rcppmlpack-examples(master)$ 

So in the case of standard (and relatively simple) package all it takes is to add one #define to the compiler flags and all is well: the newer Armadillo is used, no warnings are seen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions