1

I'm working on a linux box, with the Makevars file I created in ~/.R/Makevars containing the following:

CXX = g++
CXXSTD = -std=gnu++17

I am running R 3.5.1-intel-mkl with the following code:

library(Rcpp)
library(RcppArmadillo)
sourceCpp("code.cpp",cacheDir="~/goldfish/solvers/junkdir",rebuild=T,showOutput=T,verbose=T)

I doubt the contents of the cpp file is important as the error is referring to environmental issues:

code.cpp: In function ‘void polyRegression(const std::vector<int, std::allocator<int> >&, const std::vector<int, std::allocator<int> >&)’:
code.cpp:188:18: error: ‘transform_reduce’ is not a member of ‘std’

I tried this line of code (thanks to this answer)

g++ -x c++  -E -dM -< /dev/null | grep __cplusplus

to test for the version and this was the output:

#define __cplusplus 201402L

Which according to this answer may mean partial support. I'm a bit lost, so my questions are:

1) Is the transform_reduce method not supported in this version of g++? If not, can you recommend any alternatives? 2) If transform_reduce IS supported and I have an error in my Makevars, or the OS isn't picking it up for some reason, how do I force the OS to find it?

EDIT:

Following advice from Dirk Eddelbuettel (thanks again) I need to set all the correct variables and flags in the Makevars. I've read through this answer, too, which was enlightening, but I'm unsure what to set for C++ to compile to a version for transform_reduce to function. Here are my flags at the moment (I thought CXXSTD and CXX17STD would solve the issue, but it hasn't).

CXX = g++
CXXSTD = -std=gnu++17
CXXCPP = $(CXX) -E
CXXFLAGS = -g -O2 $(LTO)
CXXPICFLAGS = -fpic
CXX98 = g++
CXX98FLAGS = -g -O2
CXX98PICFLAGS = -fpic
CXX98STD = -std=gnu++98
CXX11 = g++
CXX11FLAGS = -g -O2
CXX11PICFLAGS = -fpic
CXX11STD = -std=gnu++11
CXX14 = g++
CXX14FLAGS = -g -O2
CXX14PICFLAGS = -fpic
CXX14STD = -std=gnu++14
CXX17 = g++
CXX17FLAGS = -g -O2
CXX17PICFLAGS = -fpic
CXX17STD = -std=gnu++17
Dr Ken Reid
  • 577
  • 4
  • 22
  • 3
    Do a quick grep or look in editor at R's own `Makeconf`, i.e. `R.home("etc/Makeconf")`. `CXX` may not be the only compiler set. Also see https://gallery.rcpp.org/articles/rcpp-and-c++11-c++14-c++17/ for a worked solution. – Dirk Eddelbuettel May 03 '20 at 03:52
  • 1
    Ah that's interesting - thank you! I had a look, and this may be the culprit: `CXX1XSTD = -std=gnu++11`. The issue is, I'm working on a shared high-powered computing server, I can't make edits to this Makevars. I was assured the local file would take precedence. So I'm still unsure where the problem is coming from - is there a test in-code that can output which Makevars is being used? – Dr Ken Reid May 03 '20 at 12:54
  • 2
    You are on the right track. Your own `~/.R/Makeconf` takes precedence _but you have to set all the right variables_. So these days I have `CXXFLAGS` as well as `CXX{{1X,11,14,17}FLAGS` in mine (and I think only the `1X` one is redundant now). – Dirk Eddelbuettel May 03 '20 at 12:58
  • Hi @DirkEddelbuettel - rather than squeeze my response here I edited the question. See the EDIT at the bottom - thanks again for your assistance! – Dr Ken Reid May 03 '20 at 13:47
  • Update: I had the same issue on my OSX, setting these in my `Makeconf` file sorted it there: `CXX11STD = -std=gnu++17` and `CXX = clang++ -std=gnu++17`. Of course that's OSX instead of Linux, and using clang. So I tried doing similar on the server (set all flags to `-std=gnu++17`) but same error, although now do see in the output of `sourcecpp` that it is indeed using `g++ -std=gnu++17`. Weird that it's using the right compiler but the issue is still present. – Dr Ken Reid May 04 '20 at 15:41
  • I am sorry that you still have to work this out but nobody can help with a [minimally complete and verifiable example](https://stackoverflow.com/help/mcve). – Dirk Eddelbuettel May 04 '20 at 15:43

0 Answers0