stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.04k stars 269 forks source link

C++14 standard requested but CXX14 is not defined #892

Open kcmtest opened 3 years ago

kcmtest commented 3 years ago
Error in .shlib_internal(args) : 
  C++14 standard requested but CXX14 is not defined
* removing ‘/usr/lib64/R/library/rstan’
Error: Failed to install 'ggstatsplot' from GitHub:
  Failed to install 'tidyBF' from GitHub:
  (converted from warning) installation of package ‘rstan’ had non-zero exit status

My R version
R version 3.6.0 (2019-04-26) -- "Planting of a Tree"

This is my OS version.

CentOS Linux release 7.9.2009 (Core)

How do i get around this? the above issue

jeffpollock9 commented 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
kcmtest commented 3 years ago

can I simply copy paste this? im not able to find the Makevars

jeffpollock9 commented 3 years ago

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.

gersonjr commented 2 years ago

I got:

 error: unrecognized command line option ‘-std=c++14’
jeffpollock9 commented 2 years ago

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.

gersonjr commented 2 years ago

@jeffpollock9 , that's probably the case. This is what I have:

c++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
jeffpollock9 commented 2 years ago

@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.

andrjohns commented 2 years ago

Unfortunately the minimum supported gcc version is 4.9.3

tedmoorman commented 2 years ago

@jeffpollock9 That ~/.R/Makevars file you posted is gold. Thank you so much!

mahboob82 commented 2 years ago

I also faced similar problems with C++14 flags errors and @jeffpollock9 's solution solved my problems. Thanks to @jeffpollock9 for your kind sharing :)

subhomoyghosh commented 2 years ago

The Makevars posted by @jeffpollock9 still shines bright! Thanks.

Neofiji commented 2 years ago

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

silvaden commented 2 years ago

@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.

bob-carpenter commented 2 years ago

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.

silvaden commented 2 years ago

@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!

bob-carpenter commented 2 years ago

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/

andrjohns commented 2 years ago

@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

abbasatdn commented 1 year ago

I went through the solutions above but I still receive the following error when trying to publish my files on on connect server image