Open kcmtest opened 3 years ago
I think the best fix is to add a ~/.R/Makevars
file which contains a line like CXX14=g++
(or whatever compiler you'd like to use for packages which require a C++-14 compliant compiler) my file looks like this:
$ cat ~/.R/Makevars
MAKEFLAGS = -j8
## C++ flags
CXX=g++
CXX11=g++
CXX14=g++
CXX17=g++
CXXFLAGS=-O3 -march=native -Wno-ignored-attributes
CXX11FLAGS=-O3 -march=native -Wno-ignored-attributes
CXX14FLAGS=-O3 -march=native -Wno-ignored-attributes
CXX17FLAGS=-O3 -march=native -Wno-ignored-attributes
CXXPICFLAGS=-fPIC
CXX11PICFLAGS=-fPIC
CXX14PICFLAGS=-fPIC
CXX17PICFLAGS=-fPIC
CXX11STD=-std=c++11
CXX14STD=-std=c++14
CXX17STD=-std=c++17
## C flags
CC=gcc
CFLAGS=-O3 -march=native
## Fortran flags
FC=gfortran
F77=gfortran
FFLAGS=-O3 -march=native
FCFLAGS=-O3 -march=native
can I simply copy paste this? im not able to find the Makevars
You could try, I don't know what c/c++ compilers you have on your system so using g++ etc might not be right for you. Also in the first line I set -j8 as I have 8 cores on my machine.
You won't have this file by default so you'll need to create it. If you Google "R Makevars" you should get some more information.
I got:
error: unrecognized command line option ‘-std=c++14’
I got:
error: unrecognized command line option ‘-std=c++14’
@gersonjr what C++ compiler + version are you using? Could be quite old and wouldn't have c++14 support.
@jeffpollock9 , that's probably the case. This is what I have:
c++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
@gersonjr that's a really old compiler which I don't think has full C++14 support, IIRC you can turn on partial support with -std=c++1y
which might be enough.
Unfortunately the minimum supported gcc version is 4.9.3
@jeffpollock9 That ~/.R/Makevars
file you posted is gold. Thank you so much!
I also faced similar problems with C++14 flags errors and @jeffpollock9 's solution solved my problems. Thanks to @jeffpollock9 for your kind sharing :)
The Makevars posted by @jeffpollock9 still shines bright! Thanks.
Under the following settings: R version 3.5.1 (2018-07-02) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19044) Rtools 3.5
Using the following codes:
install.packages("pkgbuild")
rt_path = gsub("\","/",pkgbuild::rtools_path(),fixed=T) rt_bin = paste0(substr(rt_path,1,nchar(rtpath)-4),"/mingw$(WIN)/bin/") writeLines(paste0('PATH="',rt_path,';${PATH}"'), con = "~/.Renviron") writeLines(paste0('Sys.setenv(BINPREF = "',rt_bin,'")'), con = "~/.Rprofile")
dotR <- file.path(Sys.getenv("HOME"), ".R") if (!file.exists(dotR)) dir.create(dotR) M <- file.path(dotR, "Makevars.win") if (!file.exists(M)) file.create(M) cat("\n CXX14FLAGS += -mtune=native -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2", file = M, sep = "\n", append = FALSE)
cat("\nCXX14FLAGS=-O3 -Wno-unused-variable -Wno-unused-function", "CXX14 = $(BINPREF)g++ -m$(WIN) -std=c++1y", "CXX11FLAGS=-O3 -Wno-unused-variable -Wno-unused-function", file = M, sep = "\n", append = TRUE)
made it for me. Source: https://github.com/stan-dev/rstan/wiki/Configuring-C---Toolchain-for-Windows https://community.rstudio.com/t/error-in-shlib-internal-args-c-14-standard-requested-but-cxx14-is-not-defined/16819/2
@gersonjr did you ever end up getting this working? I have the same gcc version as you on the server I am working on and I am trying to get this working for my dissertation.
If you only need to fit models, you might want to try cmdstanr. It has fewer dependencies with R and is thus easier to install.
If you need to do Laplace approximations or evaluate log densities or gradients or transforms or run Stan functions in R, you'll still need RStan.
@bob-carpenter I think I just need to run models and get estimates, I bet I can pipe the output back into R if I need to. Thanks for the suggested workaround!
Exactly---cmdstanR
itself does the plumbing around CmdStan to pipe the draws back into R and provide estimates, convergence diagnostics, and quantiles. Here's the place to get started: https://mc-stan.org/cmdstanr/
@silvaden If your gcc
version is only 4.8.5 then unfortunately you won't be able to work with the current release of Stan, regardless of which interface you use - since we rely on many c++14 features that aren't available in that version of gcc
If you have no other choice, then you may have to resort to using a much older version of Stan which did not need the c++14 features.
I previously worked out which versions of rstan
and StanHeaders
would be needed for these older pre-c++14 cases over in this forum post: https://discourse.mc-stan.org/t/problem-installing-brms-package-on-linux-server/20817/17
I went through the solutions above but I still receive the following error when trying to publish my files on on connect server
How do i get around this? the above issue