Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compilation problem on Mac 12.0.1 with M1 chip #23

Open
stephens999 opened this issue Nov 18, 2021 · 7 comments
Open

compilation problem on Mac 12.0.1 with M1 chip #23

stephens999 opened this issue Nov 18, 2021 · 7 comments

Comments

@stephens999
Copy link

I am running Mac OS Monterey, v12.0.1, on an MacBook Pro with M1 chip (13-inch, M1, 2020).

I have Apple clang version 13.0.0 (clang-1300.0.29.3)
and R version 4.1.0 Patched (2021-07-20 r80657)

I'm getting various warnings and ultimately errors when I try to compile from source.
Any ideas you might have are most welcome.

installing the source package ‘sparseMatrixStats’

trying URL 'https://bioconductor.org/packages/3.13/bioc/src/contrib/sparseMatrixStats_1.4.2.tar.gz'
Content type 'application/x-gzip' length 703959 bytes (687 KB)
==================================================
downloaded 687 KB

* installing *source* package ‘sparseMatrixStats’ ...
** using staged installation
** libs
/usr/bin/g++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/Rcpp/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c RcppExports.cpp -o RcppExports.o
/usr/bin/g++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/Rcpp/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c SparseMatrixView.cpp -o SparseMatrixView.o
In file included from SparseMatrixView.cpp:3:
./VectorSubsetView.h:32:31: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using iterator_category = std::forward_iterator_tag;
                              ^
./VectorSubsetView.h:33:24: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using value_type = stored_type;
                       ^
./VectorSubsetView.h:34:23: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using reference = stored_type;
                      ^
./VectorSubsetView.h:35:21: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using pointer = stored_type const * ;
                    ^
./VectorSubsetView.h:36:29: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using difference_type = ptrdiff_t;
                            ^
5 warnings generated.
/usr/bin/g++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/Rcpp/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c methods.cpp -o methods.o
In file included from methods.cpp:3:
In file included from ./ColumnView.h:6:
./VectorSubsetView.h:32:31: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using iterator_category = std::forward_iterator_tag;
                              ^
./VectorSubsetView.h:33:24: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using value_type = stored_type;
                       ^
./VectorSubsetView.h:34:23: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using reference = stored_type;
                      ^
./VectorSubsetView.h:35:21: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using pointer = stored_type const * ;
                    ^
./VectorSubsetView.h:36:29: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using difference_type = ptrdiff_t;
                            ^
In file included from methods.cpp:3:
./ColumnView.h:28:30: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using iterator_category= std::input_iterator_tag;
                             ^
./ColumnView.h:29:24: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using value_type = col_container;
                       ^
./ColumnView.h:30:23: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using reference = col_container&;
                      ^
./ColumnView.h:31:21: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using pointer = col_container*;
                    ^
./ColumnView.h:32:29: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using difference_type = void;
                            ^
In file included from methods.cpp:5:
./SkipNAVectorSubsetView.h:31:31: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using iterator_category = std::forward_iterator_tag;
                              ^
./SkipNAVectorSubsetView.h:32:24: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using value_type = stored_type;
                       ^
./SkipNAVectorSubsetView.h:33:23: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using reference = stored_type;
                      ^
./SkipNAVectorSubsetView.h:34:21: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using pointer = stored_type const * ;
                    ^
./SkipNAVectorSubsetView.h:35:29: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using difference_type = ptrdiff_t;
                            ^
In file included from methods.cpp:7:
./sample_rank.h:21:32: error: expected expression
  sort(indx.begin(),indx.end(),[&vec](int i1, int i2){
                               ^
./sample_rank.h:88:13: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
  for(int zp: zero_pos){
            ^
In file included from methods.cpp:8:
./my_utils.h:11:18: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
    for(double e : iter){
                 ^
./my_utils.h:22:55: error: a space is required between consecutive right angle brackets (use '> >')
std::vector<T> flatten(const std::vector<std::vector<T>>& v) {
                                                      ^~
                                                      > >
./my_utils.h:24:16: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
    for (const auto& sub : v){
               ^
./my_utils.h:24:26: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
    for (const auto& sub : v){
                         ^
./my_utils.h:29:16: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
    for (const auto& sub : v)
               ^
./my_utils.h:29:26: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
    for (const auto& sub : v)
                         ^
./my_utils.h:37:50: error: expected expression
    return std::any_of(iter.begin(), iter.end(), [](const double d) -> bool {
                                                 ^
./my_utils.h:45:51: error: expected expression
    return  std::all_of(iter.begin(), iter.end(), [](const double d) -> bool {
                                                  ^
methods.cpp:22:7: error: expected expression
      [op](ColumnView::col_container col) -> double {
      ^
methods.cpp:29:7: error: expected expression
      [op](ColumnView::col_container col) -> double {
      ^
methods.cpp:44:20: error: expected expression
                   [op](ColumnView::col_container col) -> int {
                   ^
methods.cpp:51:20: error: expected expression
                   [op](ColumnView::col_container col) -> int {
                   ^
methods.cpp:66:20: error: expected expression
                   [op](ColumnView::col_container col) -> int {
                   ^
methods.cpp:73:20: error: expected expression
                   [op](ColumnView::col_container col) -> int {
                   ^
methods.cpp:115:20: error: expected expression
                   [op](ColumnView::col_container col) -> std::vector<double> {
                   ^
methods.cpp:122:20: error: expected expression
                   [op](ColumnView::col_container col) -> std::vector<double> {
                   ^
methods.cpp:141:18: error: expected expression
                 [op](ColumnView::col_container col) -> std::vector<double> {
                 ^
methods.cpp:161:20: error: expected expression
                   [op](ColumnView::col_container col) -> std::vector<int> {
                   ^
methods.cpp:168:20: error: expected expression
                   [op](ColumnView::col_container col) -> std::vector<int> {
                   ^
methods.cpp:187:18: error: expected expression
                 [op](ColumnView::col_container col) -> std::vector<int> {
                 ^
methods.cpp:222:16: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
  for(double d : values){
               ^
methods.cpp:301:18: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
    for(double d : values){
                 ^
methods.cpp:360:5: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
    auto val_it = values.begin();
    ^
methods.cpp:361:5: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
    auto val_end = values.end();
    ^
methods.cpp:362:5: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
    auto ind_it = row_indices.begin();
    ^
methods.cpp:363:5: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
    auto ind_end = row_indices.end();
    ^
methods.cpp:399:5: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
    auto min_iter = std::min_element(values.begin(), values.end(), [](double a, double b) -> bool {
    ^
methods.cpp:399:68: error: expected expression
    auto min_iter = std::min_element(values.begin(), values.end(), [](double a, double b) -> bool {
                                                                   ^
methods.cpp:426:5: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
    auto max_iter = std::max_element(values.begin(), values.end(), [](double a, double b) -> bool {
    ^
methods.cpp:426:68: error: expected expression
    auto max_iter = std::max_element(values.begin(), values.end(), [](double a, double b) -> bool {
                                                                   ^
methods.cpp:466:58: error: expected expression
    std::sort(sorted_values.begin(), sorted_values.end(),[](double i1, double i2){
                                                         ^
methods.cpp:519:5: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
    auto max_iter = std::max_element(values.begin(), values.end(), [](double a, double b) -> bool {
    ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
30 warnings and 20 errors generated.
make: *** [methods.o] Error 1
ERROR: compilation failed for package ‘sparseMatrixStats’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/sparseMatrixStats’

The downloaded source packages are in
	‘/private/var/folders/1f/d96lz9ts15g81dqs_hcc_9cr0000gq/T/RtmpnEZa9U/downloaded_packages’
Warning messages:
1: In .inet_warning(msg) :
  unable to access index for repository https://bioconductor.org/packages/3.13/bioc/bin/macosx/big-sur-arm64/contrib/4.1:
  cannot open URL 'https://bioconductor.org/packages/3.13/bioc/bin/macosx/big-sur-arm64/contrib/4.1/PACKAGES'
2: In .inet_warning(msg) :
  unable to access index for repository https://bioconductor.org/packages/3.13/data/annotation/bin/macosx/big-sur-arm64/contrib/4.1:
  cannot open URL 'https://bioconductor.org/packages/3.13/data/annotation/bin/macosx/big-sur-arm64/contrib/4.1/PACKAGES'
3: In .inet_warning(msg) :
  unable to access index for repository https://bioconductor.org/packages/3.13/data/experiment/bin/macosx/big-sur-arm64/contrib/4.1:
  cannot open URL 'https://bioconductor.org/packages/3.13/data/experiment/bin/macosx/big-sur-arm64/contrib/4.1/PACKAGES'
4: In .inet_warning(msg) :
  unable to access index for repository https://bioconductor.org/packages/3.13/workflows/bin/macosx/big-sur-arm64/contrib/4.1:
  cannot open URL 'https://bioconductor.org/packages/3.13/workflows/bin/macosx/big-sur-arm64/contrib/4.1/PACKAGES'
5: In .inet_warning(msg) :
  unable to access index for repository https://bioconductor.org/packages/3.13/books/bin/macosx/big-sur-arm64/contrib/4.1:
  cannot open URL 'https://bioconductor.org/packages/3.13/books/bin/macosx/big-sur-arm64/contrib/4.1/PACKAGES'
6: In .inet_warning(msg) :
  installation of package ‘sparseMatrixStats’ had non-zero exit status
@stephens999
Copy link
Author

hmm.. this worked:

withr::with_makevars(
+     new = c(CXX14 = "g++", CXX14FLAGS = "-g -O2 $(LTO)", 
+             CXX14PICFLAGS = "-fpic", CXX14STD = "-std=gnu++14"), 
+     code = {
+         BiocManager::install("sparseMatrixStats")
+     })

I don't actually understand why but feel free to close this if you do not have anything to add...

@stephens999
Copy link
Author

just to add: i did previously try the other suggested solution of editing the Makevars file and that did not work,
so I did not try the above approach until a colleague suggested it....

@PeteHaitch
Copy link
Contributor

PeteHaitch commented Nov 19, 2021

Perhaps tangential to the issue, but Bioconductor is not producing M1 binaries at the moment so the package probably hasn't received much (any?) testing on the M1 platform (except perhaps via running the intel version of R under Rosetta 2). Based on this report, it looks like it might require a little work to get everything working smoothly once Bioconductor has first-class support for the M1 Macs?

@const-ae
Copy link
Owner

Hi Matthew,

thanks for flagging this. Indeed, as Pete has suggested, sparseMatrixStats hasn't really been tested on the M1, however, I am not actually sure this is an M1-specific problem. The warnings and errors suggest to me, that I actually messed up a bit with the required C++ standard:

./SkipNAVectorSubsetView.h:35:29: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
    using difference_type = ptrdiff_t;
                            ^
In file included from methods.cpp:7:
./sample_rank.h:21:32: error: expected expression
  sort(indx.begin(),indx.end(),[&vec](int i1, int i2){

For a bit of background: When I initially developed sparseMatrixStats, I decided to prioritize developer comfort over support for old compilers and used a bunch of features from the C++14 standard. I thought that being on Bioconductor, which requires the latest R version, meant that everyone would have a newish compiler. After a number of user complaints #2, #4, #14, #18, wider adoption (#18 (comment)) and friendly help from Aaron Lun I finally got rid of the C++-14 features (744adbe).

In the same commit, I removed the SystemRequirements line from the DESCRIPTION file. As far as I understand the Writing R Extensions manual, R version >=4.0 should actually use a compiler that supports C++11, but for some reason, in your specific case, it does not.

I have now re-inserted the SystemRequirements: C++11 statement (b09d608). It would be great, if you could try and install this latest version from Github and tell me if that fixed problem

devtools::install_github("const-ae/sparseMatrixStats")

Best,
Constantin

@stephens999
Copy link
Author

first try compilation looked successful but then got this error:

Error: package ‘MatrixGenerics’ 1.4.3 was found, but >= 1.5.3 is required by ‘sparseMatrixStats’
Execution halted
ERROR: lazy loading failed for package ‘sparseMatrixStats’

So I tried installing MatrixGenerics -- this updated a bunch of packages but finished with

Warning message:
package(s) not installed when version(s) same as current; use force = TRUE to re-install:
'MatrixGenerics'

I'm not sure what is going on here, but it seems likely a different problem than before....

@stephens999
Copy link
Author

not sure if this output might be relevant. Maybe there is something weird about my setup
that is making it install an old version of MatrixGenerics?

BiocManager::install("MatrixGenerics",force=TRUE)
'getOption("repos")' replaces Bioconductor standard repositories, see '?repositories' for
details

replacement repositories:
CRAN: https://cran.rstudio.com/

@PottsC
Copy link

PottsC commented Dec 9, 2021

Hi, I was experiencing similar compiling problems, and this worked for me as well.

hmm.. this worked:

withr::with_makevars(
+     new = c(CXX14 = "g++", CXX14FLAGS = "-g -O2 $(LTO)", 
+             CXX14PICFLAGS = "-fpic", CXX14STD = "-std=gnu++14"), 
+     code = {
+         BiocManager::install("sparseMatrixStats")
+     })

I don't actually understand why but feel free to close this if you do not have anything to add...

  • Operating system with exact version
    Linux RedHat 3.10.0-1127.13.1.e17.x86_64

  • Compiler and compiler version
    gcc version 7.3.1

  • The output of sessionInfo()

R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux
 
Matrix products: default
BLAS/LAPACK: /usr/lib64/libopenblasp-r0.3.3.so
 
locale:
[1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8  
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C           
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C      
 
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base    
 
loaded via a namespace (and not attached):
[1] BiocManager_1.30.16 compiler_4.0.2      tools_4.0.2         withr_2.4.3
  • Information if you have a ~/.R/Makevars file and what it contains
    no Makevars file

  • The exact call that you use to install sparseMatrixStats including the full error message

'getOption("repos")' replaces Bioconductor standard repositories, see '?repositories' for details
 
replacement repositories:
    CRAN: https://cran.rstudio.com/

Bioconductor version 3.12 (BiocManager 1.30.16), R 4.0.2 (2020-06-22)
Installing package(s) 'sparseMatrixStats'
trying URL 'https://bioconductor.org/packages/3.12/bioc/src/contrib/sparseMatrixStats_1.2.1.tar.gz'
Content type 'application/x-gzip' length 698554 bytes (682 KB)
==================================================
downloaded 682 KB

* installing *source* package ‘sparseMatrixStats’ ...
** using staged installation
** libs
Error: C++14 standard requested but CXX14 is not defined
* removing ‘/home/[email protected]/R/x86_64-pc-linux-gnu-library/4.0/sparseMatrixStats’

The downloaded source packages are in
        ‘/tmp/Rtmp9NbNWX/downloaded_packages’
Installation paths not writeable, unable to update packages
  path: /opt/R/4.0.2/lib/R/library
  packages:
    arrow, backports, blob, bookdown, boot, brio, broom, broom.helpers, broom.mixed, bslib, cachem, class, cli, cluster, colorspace,
    conflicted, cpp11, crayon, credentials, crosstalk, curl, data.table, DatabaseConnector, datamods, dbplyr, desc, devtools, dials, diffobj,
    digest, dplyr, DT, ellipsis, fansi, fs, future, generics, gert, ggplot2, gh, git2r, glue, gt, gtools, gtsummary, haven, highr, Hmisc, hms,
    htmlTable, htmltools, htmlwidgets, httpuv, infer, ipred, isoband, jquerylib, KernSmooth, knitr, labelled, later, lattice, lava, lhs,
    lifecycle, lubridate, MASS, Matrix, memoise, mgcv, mime, nlme, nnet, odbc, openssl, packrat, parallelly, pillar, pins, pkgbuild, pkgload,
    plotly, pROC, R6, Rcpp, readr, recipes, REDCapR, remotes, reprex, rio, rJava, rlang, rmarkdown, rsample, rsconnect, rvest, sass, seriation,
    shiny, shinydashboard, shinyWidgets, spatial, SqlRender, stringi, survival, testthat, tibble, tidymodels, tidyr, tidyselect, tidyverse,
    tinytex, TMB, TSP, usethis, utf8, vctrs, viridis, waldo, withr, workflows, xfun, xml2, yardstick, zip
Warning message:
In .inet_warning(msg) :
  installation of package ‘sparseMatrixStats’ had non-zero exit status

Just wanted to share this and say thanks to stephens999 for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants