stephenslab / mixsqp

R package for fast maximum-likelihood estimation of mixture proportions using SQP.
https://bit.ly/2NtYHWT
Other
11 stars 7 forks source link

Compile error on Apple Silicon chip #50

Open gaow opened 1 year ago

gaow commented 1 year ago

Error message

When I run

 devtools::install_github('stephenslab/mixsqp')

on my new Mac with Apple M2 Pro and MacOS 13.2.1, I get:

/Users/gw2411/micromamba/envs/pisces-rabbit/lib/R/library/RcppArmadillo/include/armadillo_bits/fn_misc.hpp:172:21: error: no member named 'Rlog1p' in namespace 'std'; did you mean simply 'Rlog1p'?
    return (log_a + std::log1p(std::exp(negdelta)));
                    ^~~~~~~~~~
                    Rlog1p

It fails to install. This also prevents susieR from installing on my new Mac.

Environment

Compiler:

arm64-apple-darwin20.0.0-clang

R session

sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: aarch64-apple-darwin20.0.0 (64-bit)
Running under: macOS Ventura 13.2.1

Matrix products: default
BLAS/LAPACK: /Users/gw2411/micromamba/envs/pisces-rabbit/lib/libopenblas.0.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/New_York
tzcode source: system (macOS)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] colorout_1.2-2 pacman_0.5.1

loaded via a namespace (and not attached):
 [1] miniUI_0.1.1.1    compiler_4.3.1    crayon_1.5.2      promises_1.2.1    Rcpp_1.0.11       stringr_1.5.0     callr_3.7.3       later_1.3.1       fastmap_1.1.1     mime_0.12
[11] R6_2.5.1          curl_5.0.2        htmlwidgets_1.6.2 desc_1.4.2        profvis_0.3.8     rprojroot_2.0.3   shiny_1.7.5       rlang_1.1.1       cachem_1.0.8      stringi_1.7.12
[21] httpuv_1.6.11     fs_1.6.3          pkgload_1.3.2.1   memoise_2.0.1     cli_3.6.1         magrittr_2.0.3    ps_1.7.5          digest_0.6.33     processx_3.8.2    xtable_1.8-4
[31] remotes_2.4.2.1   devtools_2.4.5    lifecycle_1.0.3   prettyunits_1.2.0 vctrs_0.6.3       glue_1.6.2        urlchecker_1.0.1  sessioninfo_1.2.2 pkgbuild_1.4.2    purrr_1.0.2
[41] usethis_2.2.2     tools_4.3.1       ellipsis_0.3.2    htmltools_0.5.6

Solution

After applying this fix to src/Makevars

--- a/src/Makevars
+++ b/src/Makevars
@@ -1,4 +1,4 @@
 CXX_STD = CXX11
-PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) -DARMA_DONT_PRINT_ERRORS \
+PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) -DARMA_DONT_PRINT_ERRORS -DHAVE_WORKING_LOG1P \
   -DARMA_NO_DEBUG -DARMA_USE_BLAS -DARMA_DONT_USE_OPENMP -DARMA_WARN_LEVEL=1

It works fine. This also works on Linux OS but i'm not sure if this is a proper fix. @pcarbo what do you think --- would you like to try it out and see?

pcarbo commented 1 year ago

@gaow Did you download the R compiler tools compatible with your Mac? See here.

gaow commented 1 year ago

@pcarbo No i used the compiler that came from brew. Just got a chance to check the link you sent, which seem to suggest we need the tools for Fortran packages so I doubt it is relevant to this issue? According to this ticket, recompile R from source solves the issue. I wonder if you have an Apple Silicon chip machine with the proper setup as you suggested but not R compiled from source code, to test if the tools you pointed out is sufficient solution?

pcarbo commented 1 year ago

@gaow I think you are using the wrong C/C++ compiler. As it says on CRAN, you need to use the compilers included with XCode:

"This release uses Xcode 14.2/14.3 and GNU Fortran 12.2. If you wish to compile R packages which contain Fortran code, you may need to download the corresponding GNU Fortran compiler from https://mac.r-project.org/tools/. Any external libraries and tools are expected to live in /opt/R/arm64 (Apple silicon) or /opt/R/x86_64 (Intel)."

Also make sure you are using this version of R:

For Apple silicon (M1/M2) Macs: R-4.3.1-arm64.pkg