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++14 standard requested but CXX14 is not defined #892

Open
kcmtest opened this issue Jan 8, 2021 · 18 comments
Open

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

kcmtest opened this issue Jan 8, 2021 · 18 comments

Comments

@kcmtest
Copy link

kcmtest commented Jan 8, 2021

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
Copy link

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
Copy link
Author

kcmtest commented Jan 9, 2021

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

@jeffpollock9
Copy link

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
Copy link

I got:

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

@jeffpollock9
Copy link

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
Copy link

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

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

@jeffpollock9
Copy link

@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
Copy link
Contributor

Unfortunately the minimum supported gcc version is 4.9.3

@tedmoorman
Copy link

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

@mahboob82
Copy link

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
Copy link

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

@Neofiji
Copy link

Neofiji commented Oct 23, 2022

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

@silvaden
Copy link

@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
Copy link

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
Copy link

@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
Copy link

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
Copy link
Contributor

andrjohns commented Oct 29, 2022

@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
Copy link

abbasatdn commented Jan 6, 2023

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

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