R package using RStan compilation error with standalone functions

I have developed a package that relies on RStan (https://github.com/plloydsmith/rmdcev) and am having installation/compilation issues on macOS Catalina 10.15.6. The package installs and passes CRAN checks on windows and ubuntu, but not on macOS Catalina 10.15.6.

The notable thing about the package is that it includes standalone Stan functions and a {packagename}_types.h file which I think is the cause of the problem (Note: to build the package I manually call expose_stan_functions on SimulationFunctions.stan, save the cpp code and remove #include <exporter.h> from the header). If I remove the standalone Stan functions, then the package can compile and install fine. The specific error I receive during compilation is

RcppExports.cpp:339:5: error: no matching function for call to 'R_useDynamicSymbols'
    R_useDynamicSymbols(dll, FALSE);
    ^~~~~~~~~~~~~~~~~~~
/Library/Frameworks/R.framework/Resources/include/R_ext/Rdynload.h:84:10: note: candidate function not viable: no known conversion from 'int' to 'Rboolean' for 2nd argument
Rboolean R_useDynamicSymbols(DllInfo *info, Rboolean value);
         ^
20 warnings and 1 error generated.
make: *** [RcppExports.o] Error 1
ERROR: compilation failed for package β€˜rmdcev’

The full error output is available here

I have spent some time trying to find a solution, but to no avail. The problem seems related to


and

Has anyone come across this problem before using RStan or have any tips?

The full session information for the build is below

─ Session info ───────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 4.0.2 (2020-06-22)
 os       macOS Catalina 10.15.6      
 system   x86_64, darwin17.0          
 ui       X11                         
 language (EN)                        
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       UTC                         
 date     2020-09-08              
─ Packages ───────────────────────────────────────────────────────────────────────────────────────
 ! package      * version   date       lib source        
   assertthat     0.2.1     2019-03-21 [1] CRAN (R 4.0.2)
   backports      1.1.9     2020-08-24 [1] CRAN (R 4.0.2)
   base         * 4.0.2     2020-06-23 [?] local         
   base64enc      0.1-3     2015-07-28 [1] CRAN (R 4.0.2)
   BH             1.72.0-3  2020-01-08 [1] CRAN (R 4.0.2)
   boot           1.3-25    2020-04-26 [2] CRAN (R 4.0.2)
   callr          3.4.4     2020-09-07 [1] CRAN (R 4.0.2)
   checkmate      2.0.0     2020-02-06 [1] CRAN (R 4.0.2)
   class          7.3-17    2020-04-26 [2] CRAN (R 4.0.2)
   cli            2.0.2     2020-02-28 [1] CRAN (R 4.0.2)
   cluster        2.1.0     2019-06-19 [2] CRAN (R 4.0.2)
   codetools      0.2-16    2018-12-24 [2] CRAN (R 4.0.2)
   colorspace     1.4-1     2019-03-18 [1] CRAN (R 4.0.2)
 P compiler       4.0.2     2020-06-23 [2] local         
   cpp11          0.2.1     2020-08-11 [1] CRAN (R 4.0.2)
   crayon         1.3.4     2017-09-16 [1] CRAN (R 4.0.2)
   curl           4.3       2019-12-02 [1] CRAN (R 4.0.1)
 P datasets     * 4.0.2     2020-06-23 [2] local         
   desc           1.2.0     2018-05-01 [1] CRAN (R 4.0.2)
   digest         0.6.25    2020-02-23 [1] CRAN (R 4.0.2)
   dplyr          1.0.2     2020-08-18 [1] CRAN (R 4.0.2)
   ellipsis       0.3.1     2020-05-15 [1] CRAN (R 4.0.2)
   evaluate       0.14      2019-05-28 [1] CRAN (R 4.0.1)
   fansi          0.4.1     2020-01-08 [1] CRAN (R 4.0.2)
   farver         2.0.3     2020-01-16 [1] CRAN (R 4.0.2)
   foreign        0.8-80    2020-05-24 [2] CRAN (R 4.0.2)
   Formula        1.2-3     2018-05-03 [1] CRAN (R 4.0.2)
   generics       0.0.2     2018-11-29 [1] CRAN (R 4.0.2)
   ggplot2        3.3.2     2020-06-19 [1] CRAN (R 4.0.2)
   glue           1.4.2     2020-08-27 [1] CRAN (R 4.0.2)
 P graphics     * 4.0.2     2020-06-23 [2] local         
 P grDevices    * 4.0.2     2020-06-23 [2] local         
   grid           4.0.2     2020-06-23 [?] local         
   gridExtra      2.3       2017-09-09 [1] CRAN (R 4.0.2)
   gtable         0.3.0     2019-03-25 [1] CRAN (R 4.0.2)
   highr          0.8       2019-03-20 [1] CRAN (R 4.0.2)
   htmltools      0.5.0     2020-06-16 [1] CRAN (R 4.0.2)
   inline         0.3.16    2020-09-06 [1] CRAN (R 4.0.2)
   isoband        0.2.2     2020-06-20 [1] CRAN (R 4.0.2)
   jsonlite       1.7.1     2020-09-07 [1] CRAN (R 4.0.2)
   KernSmooth     2.23-17   2020-04-26 [2] CRAN (R 4.0.2)
   knitr          1.29      2020-06-23 [1] CRAN (R 4.0.2)
   labeling       0.3       2014-08-23 [1] CRAN (R 4.0.2)
   lattice        0.20-41   2020-04-02 [2] CRAN (R 4.0.2)
   lifecycle      0.2.0     2020-03-06 [1] CRAN (R 4.0.2)
   loo            2.3.1     2020-07-14 [1] CRAN (R 4.0.2)
   magrittr       1.5       2014-11-22 [1] CRAN (R 4.0.2)
   markdown       1.1       2019-08-07 [1] CRAN (R 4.0.2)
   MASS           7.3-51.6  2020-04-26 [2] CRAN (R 4.0.2)
   Matrix         1.2-18    2019-11-27 [2] CRAN (R 4.0.2)
   matrixStats    0.56.0    2020-03-13 [1] CRAN (R 4.0.2)
 P methods      * 4.0.2     2020-06-23 [2] local         
   mgcv           1.8-31    2019-11-09 [2] CRAN (R 4.0.2)
   mime           0.9       2020-02-04 [1] CRAN (R 4.0.2)
   munsell        0.5.0     2018-06-12 [1] CRAN (R 4.0.2)
   nlme           3.1-148   2020-05-24 [2] CRAN (R 4.0.2)
   nnet           7.3-14    2020-04-26 [2] CRAN (R 4.0.2)
   parallel       4.0.2     2020-06-23 [?] local         
   pillar         1.4.6     2020-07-10 [1] CRAN (R 4.0.2)
   pkgbuild       1.1.0     2020-07-13 [1] CRAN (R 4.0.2)
   pkgconfig      2.0.3     2019-09-22 [1] CRAN (R 4.0.2)
   pkgload        1.1.0     2020-05-29 [1] CRAN (R 4.0.2)
   praise         1.0.0     2015-08-11 [1] CRAN (R 4.0.2)
   prettyunits    1.1.1     2020-01-24 [1] CRAN (R 4.0.2)
   processx       3.4.4     2020-09-03 [1] CRAN (R 4.0.2)
   ps             1.3.4     2020-08-11 [1] CRAN (R 4.0.2)
   purrr          0.3.4     2020-04-17 [1] CRAN (R 4.0.2)
   R6             2.4.1     2019-11-12 [1] CRAN (R 4.0.2)
   rcmdcheck      1.3.3     2019-05-07 [1] CRAN (R 4.0.2)
   RColorBrewer   1.1-2     2014-12-07 [1] CRAN (R 4.0.2)
   Rcpp           1.0.5     2020-07-06 [1] CRAN (R 4.0.2)
   RcppEigen      0.3.3.7.0 2019-11-16 [1] CRAN (R 4.0.2)
   RcppParallel   5.0.2     2020-06-24 [1] CRAN (R 4.0.2)
   remotes        2.2.0     2020-07-21 [1] CRAN (R 4.0.2)
   rlang          0.4.7     2020-07-09 [1] CRAN (R 4.0.2)
   rmarkdown      2.3       2020-06-18 [1] CRAN (R 4.0.2)
   rpart          4.1-15    2019-04-12 [2] CRAN (R 4.0.2)
   rprojroot      1.3-2     2018-01-03 [1] CRAN (R 4.0.2)
   rstan          2.21.2    2020-07-27 [1] CRAN (R 4.0.2)
   rstantools     2.1.1     2020-07-06 [1] CRAN (R 4.0.2)
   rstudioapi     0.11      2020-02-07 [1] CRAN (R 4.0.2)
   scales         1.1.1     2020-05-11 [1] CRAN (R 4.0.2)
   sessioninfo    1.1.1     2018-11-05 [1] CRAN (R 4.0.2)
   spatial        7.3-12    2020-04-26 [2] CRAN (R 4.0.2)
   splines        4.0.2     2020-06-23 [?] local         
   StanHeaders    2.21.0-6  2020-08-16 [1] CRAN (R 4.0.2)
 P stats        * 4.0.2     2020-06-23 [2] local         
   stats4         4.0.2     2020-06-23 [?] local         
   stringi        1.4.6     2020-02-17 [1] CRAN (R 4.0.2)
   stringr        1.4.0     2019-02-10 [1] CRAN (R 4.0.2)
   survival       3.1-12    2020-04-10 [2] CRAN (R 4.0.2)
   tcltk          4.0.2     2020-06-23 [?] local         
   testthat       2.3.2     2020-03-02 [1] CRAN (R 4.0.2)
   tibble         3.0.3     2020-07-10 [1] CRAN (R 4.0.2)
   tidyr          1.1.2     2020-08-27 [1] CRAN (R 4.0.2)
   tidyselect     1.1.0     2020-05-11 [1] CRAN (R 4.0.2)
   tinytex        0.25      2020-07-24 [1] CRAN (R 4.0.2)
 P tools          4.0.2     2020-06-23 [2] local         
   utf8           1.1.4     2018-05-24 [1] CRAN (R 4.0.2)
 P utils        * 4.0.2     2020-06-23 [2] local         
   V8             3.2.0     2020-06-19 [1] CRAN (R 4.0.2)
   vctrs          0.3.4     2020-08-29 [1] CRAN (R 4.0.2)
   viridisLite    0.3.0     2018-02-01 [1] CRAN (R 4.0.1)
   withr          2.2.0     2020-04-20 [1] CRAN (R 4.0.2)
   xfun           0.16      2020-07-24 [1] CRAN (R 4.0.2)
   xopen          1.0.0     2018-09-17 [1] CRAN (R 4.0.2)
   yaml           2.2.1     2020-02-01 [1] CRAN (R 4.0.2)

Has anything changed in rmdcev since the last time we created those functions?

Yes there have been quite a few changes to the overall package and the Stan functions themselves. In previous versions of the package I did not have continuous testing on mac OS so I am not sure if one of these changes is causing the issue or if the package always struggled on mac OS.

As a test, I tried to mimic the changes implemented here to exporter.h and create a separate exporter_temp.h file in the package with

#ifdef FALSE
 #undef FALSE
#endif

near the end but that did not seem to make a difference.

I’m a bit stumped at this point as I’ve followed the same manual procedure you provide in the link and the package compiles/installs fine on mac OS if I remove the standalone functions code so I don’t think its an issue with other aspects.

I’ll keep debugging away and was curious if anyone else had a working version of a package with standalone functions.

For posterity’s sake, I managed to solve this issue by removing the third line of the pkgname_types.h file

#include <stan/model/standalone_functions_header.hpp>