Problem Installing cmdstan on Surface Pro 9 with Windows 11

I am using R version 4.3.2 (2023-10-31 ucrt) – “Eye Holes” and want to install cmdstanr. When using

install_cmdstan()

I get the error message

In file included from c:\rtools43\x86_64-w64-mingw32.static.posix\lib\gcc\x86_64-w64-mingw32.static.posix\12.3.0\include\c++\fstream:1298,
                 from stan/src/stan/model/model_header.hpp:18:
c:\rtools43\x86_64-w64-mingw32.static.posix\lib\gcc\x86_64-w64-mingw32.static.posix\12.3.0\include\c++\bits\fstream.tcc:1100:1: fatal error: cannot write PCH file: required memory segment unavailable
 1100 | } // namespace std
      | ^
compilation terminated.
make: *** [make/program:30: stan/src/stan/model/model_header.hpp.gch/model_header_12_3.hpp.gch] Error 1
make: *** Waiting for unfinished jobs....

I tried cleaning up the PCH files but somehow it won’t fix the problem…Has anyone an idea how to solve this issue? I am working on a Surface Pro 9 under Windows 11. I will try it later on my desktop computer, maybe its a specific problem related to the surface laptop.

Many thanks!

Edit. Indeed, on my desktop it does work flawlessly! It must be a problem with the surface laptop. Anyway, I work with my desktop from now on, but it should still be interesting to know why it doesn’t work on the surface pro 9!

It’s this known issue. Though I don’t know which exact platforms are affected or the best solution. I would guess that disabling pre-compiled headers would fix it.

Fatal error with PCH compilation · Issue #108 · brechtsanders/winlibs_mingw · GitHub Fatal error with PCH compilation · Issue #108 · brechtsanders/winlibs_mingw · GitHub

2 Likes

The easiest way to do this is create a file at $CMDSTAN/make/local with the text PRECOMPILED_HEADERS=false

1 Like

I tried this by opening the local file which already had the text:
CXXFLAGS += -Wno-nonnull -D_UCRT
TBB_CXXFLAGS= -D_UCRT
CXXFLAGS += -Wno-deprecated-declarations
I added the text
PRECOMPILED_HEADERS=false
above this text and again tried:
install_cmdstan(cores = 2,overwrite = TRUE)
But this produced the same error. I think this is the case because it removed the previous installation of cmdstan which had the local file above. Clearly I’m misunderstanding something. Thank you for any help you can provide.

Yes, instead of install_cmdstan(cores=2,overwrite=TRUE), try rebuild_cmdstan(cores=2)

1 Like

Thank you! That appears to have worked! I appreciate it!

1 Like