Hello all, lately I’ve been spending a lot of time helping users of my RStan-dependent package troubleshoot toolchain configuration issues when installing the package from GitHub. In the course of that, I discovered something surprising on my own system: based on the flags used in a compiled model, as reported by get_cxxflags(), the compiler seems to be ignoring the contents of my Makevars.win.
Same thing if I compile one of the much more complex Stan programs in my package (just compiling a single model, not installing the package). The flags returned by get_cxxflags() are the same as the ones shown above, not the ones in Makevars.win.
Does anyone have an idea why the compiler seems to be ignoring Makevars.win? One thought I had was that perhaps get_cxxflags() literally only reports the CXXFLAGS (of which I have none specified) and ignores the CXX14FLAGS, and/or that the models being compiled don’t require C++14 (caveat: I really have no idea what I’m talking about here). But the fact that the optimization flags, especially -O3, don’t seem to be enforced appears to be a problem.
I believe the get_cxxflags() function only returns flags that you’ve set via CXXFLAGS +=, whereas your flags are set via CXX14FLAGS +=. To verify for certain whether the flags are being respected during compilation, you can use verbose = TRUE in your stan call and look at the compilation flags that are used
Ah OK, thanks for the clarification @andrjohns. I hadn’t noticed verbose did that. I also realized it must be using Makevars.win, because the warnings when compiling my real model are suppressed.
A related question, which has also come up in these user toolchain issues I mentioned as well as my own: is the R_MAKEVARS_USER environment variable supposed to be set to ~/.R/Makevars.win or whatever by default? I don’t think it’s mentioned in the Getting Started, which led me to think it was, but I’m getting the impression it’s not set to anything. For a couple of users who’ve been bogged down with this stuff, that was the (or a) cause.
A related question, which has also come up in these user toolchain issues I mentioned as well as my own: is the R_MAKEVARS_USER environment variable supposed to be set to ~/.R/Makevars.win or whatever by default?
R looks for the makevars files (for any compilation from source as well) in the $HOME/.R directory, rather than the R_MAKEVARS_USER variable. If you have users whose Makevars settings aren’t being detected by R, the most likely cause is the .R folder not being in the $HOME directory
Oh, interesting. So R_MAKEVARS_USER may have been a red herring, except there’s at least one case (I’m pretty sure; will double-check) where the Makevars file in $HOME/.R didn’t take effect until the environment variable was set.
Anyway, thanks for taking the time to explain this stuff. Based on various threads on here, I know I’m not alone in finding these toolchain issues confusing.
Bumping this thread because I’ve once again encountered a situation where the compiler seems to be ignoring my user Makevars.win. I just upgraded from R 4.2.2 / Rtools42 to R 4.3.0 / Rtools43, and I’m still able to compile and sample models but my compiler flags, which used to work as intended, suddenly do not.
If you scroll far enough, you’ll see that it’s using -O2 instead of -O3 and my flags to suppress various warnings have been replaced with -Wall. This was not the case before upgrading; nothing else has changed.
I see that the compiler is now using C++17. This surprised me, since the rstantools-generated src/Makevars.win in my package includes the line CXX_STD = CXX14, but I tried changing all the CXX14FLAGS in my user Makevars.win to CXX17FLAGS. This made no difference. Also, my Makevars are ignored as well when compiling a standalone model where there is no package CXX_STD.
Any advice on what’s going on here and how to fix it would be greatly appreciated.