rstan icon indicating copy to clipboard operation
rstan copied to clipboard

C++14 standard requested but CXX14 is not defined

Open kcmtest opened this issue 4 years ago • 18 comments
trafficstars

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

kcmtest avatar Jan 08 '21 09:01 kcmtest

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

jeffpollock9 avatar Jan 08 '21 17:01 jeffpollock9

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

kcmtest avatar Jan 09 '21 07:01 kcmtest

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.

jeffpollock9 avatar Jan 09 '21 08:01 jeffpollock9

I got:

 error: unrecognized command line option ‘-std=c++14’

gersonjr avatar Nov 11 '21 16:11 gersonjr

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 avatar Nov 11 '21 16:11 jeffpollock9

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

c++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)

gersonjr avatar Nov 11 '21 16:11 gersonjr

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

jeffpollock9 avatar Nov 11 '21 16:11 jeffpollock9

Unfortunately the minimum supported gcc version is 4.9.3

andrjohns avatar Nov 11 '21 16:11 andrjohns

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

tedmoorman avatar Dec 15 '21 14:12 tedmoorman

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

mahboob82 avatar Jun 13 '22 01:06 mahboob82

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

subhomoyghosh avatar Aug 12 '22 23:08 subhomoyghosh

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(rt_path)-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

Neofiji avatar Oct 23 '22 12:10 Neofiji

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

silvaden avatar Oct 28 '22 00:10 silvaden

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 avatar Oct 28 '22 08:10 bob-carpenter

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

silvaden avatar Oct 28 '22 17:10 silvaden

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/

bob-carpenter avatar Oct 29 '22 09:10 bob-carpenter

@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

andrjohns avatar Oct 29 '22 09:10 andrjohns

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

abbasatdn avatar Jan 06 '23 02:01 abbasatdn