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

"C++11 compiler required; enable C++11 mode in your compiler, or use an earlier version of Armadillo" Error in Mac OS Big Sur #324

Closed
aminadibi opened this issue Jan 23, 2021 · 14 comments

Comments

@aminadibi
Copy link

aminadibi commented Jan 23, 2021

Following #268 using Mac OS Big Sur with the m1 processor running R and gfortran under Rosetta, I get the error "*** C++11 compiler required; enable C++11 mode in your compiler, or use an earlier version of Armadillo" trying to compile the following helloworld file:

#include <RcppArmadillo.h>   

// [[Rcpp::depends(RcppArmadillo)]]

// [[Rcpp::export]]
void hello_world() {
  Rcpp::Rcout << "Hello World!" << std::endl;  
}

// After compile, this function will be immediately called using
// the below snippet and results will be sent to the R console.

/*** R
hello_world() 
*/

Been on it for hours now and can't figure out what is it that I'm missing.
Here's the error:

> Rcpp::sourceCpp('./src/helloworld.cpp')
In file included from helloworld.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/RcppArmadillo.h:31:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/RcppArmadilloForward.h:49:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo:21:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/compiler_check.hpp:50:4: error: "*** C++11 compiler required; enable C++11 mode in your compiler, or use an earlier version of Armadillo"
  #error "*** C++11 compiler required; enable C++11 mode in your compiler, or use an earlier version of Armadillo"
   ^
In file included from helloworld.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/RcppArmadillo.h:31:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/RcppArmadilloForward.h:49:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo:85:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:149:12: error: unknown type name 'constexpr'
    static constexpr bool is_row  = false;
           ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:150:12: error: unknown type name 'constexpr'
    static constexpr bool is_col  = false;
           ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:151:12: error: unknown type name 'constexpr'
    static constexpr bool is_xvec = false;
           ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:161:12: error: unknown type name 'constexpr'
    static constexpr bool is_row  = false;
           ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:162:12: error: unknown type name 'constexpr'
    static constexpr bool is_col  = false;
           ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:163:12: error: unknown type name 'constexpr'
    static constexpr bool is_xvec = true;
           ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:173:12: error: unknown type name 'constexpr'
    static constexpr bool is_row  = false;
           ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:174:12: error: unknown type name 'constexpr'
    static constexpr bool is_col  = true;
           ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:175:12: error: unknown type name 'constexpr'
    static constexpr bool is_xvec = false;
           ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:185:12: error: unknown type name 'constexpr'
    static constexpr bool is_row  = true;
           ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:186:12: error: unknown type name 'constexpr'
    static constexpr bool is_col  = false;
           ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:187:12: error: unknown type name 'constexpr'
    static constexpr bool is_xvec = false;
           ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:197:12: error: unknown type name 'constexpr'
    static constexpr bool is_row  = T1::is_row;
           ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:198:12: error: unknown type name 'constexpr'
    static constexpr bool is_col  = T1::is_col;
           ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:199:12: error: unknown type name 'constexpr'
    static constexpr bool is_xvec = T1::is_xvec;
           ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:209:12: error: unknown type name 'constexpr'
    static constexpr bool is_row  = false;
           ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:210:12: error: unknown type name 'constexpr'
    static constexpr bool is_col  = false;
           ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/armadillo_bits/arma_forward.hpp:211:12: error: unknown type name 'constexpr'
    static constexpr bool is_xvec = false;
           ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [helloworld.o] Error 1
clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I../inst/include   -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include" -I"/Users/amin/armatest/src" -I"/Users/amin/armatest/src/../inst/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c helloworld.cpp -o helloworld.o
Error in Rcpp::sourceCpp("./src/helloworld.cpp") : 
  Error 1 occurred building shared library.

I have gfortran 10.2.0 through fxcoudert and clang 12.0.0 through Xcode

% gfortran --version            
GNU Fortran (GCC) 10.2.0

% clang --version
Apple clang version 12.0.0 (clang-1200.0.32.28)
Target: arm64-apple-darwin20.2.0

Here is my environment:


> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

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

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

loaded via a namespace (and not attached):
[1] compiler_4.0.3 tools_4.0.3   
@kevinushey
Copy link
Contributor

Works fine for me on Big Sur. The main thing that stands out is that your compile statement isn't requesting C++11 (or greater). E.g. when I run sourceCpp(), I see:

clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I../inst/include -I"/Users/kevinushey/Library/R/4.0/library/Rcpp/include" -I"/Users/kevinushey/Library/R/4.0/library/RcppArmadillo/include" -I"/Users/kevinushey/scratch" -I/usr/local/include -fPIC -g -O3 -pipe -Wall -pedantic -c hello.cpp -o hello.o

Note the -std=gnu++11. That comes from R's Makevars:

CXX = clang++ -mmacosx-version-min=10.13 -std=gnu++11

which makes me suspect you may have overridden CXX in your own ~/.R/Makevars.

FWIW you can force C++11 with:

// [[Rcpp::plugins(cpp11)]]

in your script as an alternate way forward.

@aminadibi
Copy link
Author

That worked! Thank you so much!

@eddelbuettel
Copy link
Member

@kevinushey Isn't the plugin redundant as R now enforces C++11 as a minimum standard? Or did you suggest it as a fudge in case a local ~/.R/Makevars shadows / invalidates the global setting?

@kevinushey
Copy link
Contributor

Right, it's a fudge in case the user has overridden the default compiler and removed the flags forcing C++11.

@aminadibi
Copy link
Author

aminadibi commented Jan 23, 2021

So, to be clear I had not manually overridden the default. After a fresh install of R and Xcode on a new laptop, there was a ~/.R/Makevars with:

CC=clang
CXX=clang++

@eddelbuettel
Copy link
Member

See #324 (comment) where @kevinushey explains what gets replaced. You are loosing that selection of C++11. Which is the issue that brought you here. Makes sense? So not pointing fingers at you per se but maybe at whoever setup of the installer?

@aminadibi
Copy link
Author

Of course @eddelbuettel. I am just curious why would R create a Makevars that overrides C++11?

@eddelbuettel
Copy link
Member

eddelbuettel commented Jan 23, 2021

"It doesn't." (Speaking at the Debian maintainre for the build of R.) R would never touch ~/.R/Makevars.

Maybe it's XCode, maybe it's a (ahem) feature in the macOS build. I have no idea.

@kevinushey
Copy link
Contributor

That might've been done by RStudio actually (if you're using that). Will have to investigate.

(That's an old leftover from the days when Apple switched from gcc to clang)

@kevinushey
Copy link
Contributor

Just to close the loop, this was quite likely generated by RStudio:

rstudio/rstudio#8800

so we'll have to fix there. Sorry for the trouble; this fix was appropriate ~5 years ago but no longer now :-/

@eddelbuettel
Copy link
Member

Glad we found it!

@aminadibi
Copy link
Author

Thanks for following up with this @kevinushey! Will save so many from so much trouble.

@Tomtao626
Copy link

-std=c++11

@eddelbuettel
Copy link
Member

@Tomtao626 R does that automatically for at least two years now, in fact it by now defaults to C++14. The root cause is still the need for recent-enough compiler on the machine.

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