Various compilation problems with various interfaces

I’m not sure where the best place is to post this, as most of the problems are with Bridgestan and I’m not sure whether these forums are supposed to cover that. However, I didn’t find a Bridgestan forum and the Github issue tracker for Bridgestan doesnt seem to be used for these types of things. If there is a better place to post this, I’d welcome a hint at that.

The short summary of the problem is:

  • No Problems with RStan
  • Cmdstanr throws lots of warnings during compile, but the model samples just fine.
  • Bridgestan in R errors out of compilation with a code 2 error.
  • Bridgestan in Julia seems to compile just fine, but then fails to load the created model file for sampling.
  • Bridgestan invoked from the command line (when executing the “bridgestan installation test” from its manual) throws lots of warnings (similar to cmdstanr), and seems to compile sucessfully (I didnt try to sample from the resulting model).

Details:

What I’ve tried:

  • Installed BridgeStan manually into C:\BridgeStan after Bridgestan in Julia auto-installed it to a path containing spaces (my windows user-name contains a space). I’m manually pointing Bridgestan in Julia (an in R) to that location.
  • Reinstalled RTools exactly following the cmdstan toolchain install instructions, which the BridgeStan instruction point to. (including setting up PATH and running
    “pacman -Sy mingw-w64-ucrt-x86_64-make mingw-w64-ucrt-x86_64-gcc” in msys2)
  • Tested with both RTools43 and RTools42 (currently both installed for testing purposes, but that wasnt the case when I started testing and the errors looked similar/identical back then).
  • Lots of googling for the error messages.

What I’m not sure about:

  • What versions of cmdstan, stan and stan-math and other dependencies each of the interfaces is using, or how to find out, and whether they are sharing this or each has its own installation. I’m assuming that these are things which users are not supposed to need to know about.

cmdstanr (version version 0.5.3, using CmdStan version: 2.30.1) returns this (the model samples just fine):



The “official BridgeStan installation test” returns this (i didnt try sampling the model):




Bridgestan in Julia (version 2.3.0) errors and returns this: (on a self-written (=possibly buggy) model, Julia version 1.10.0)
(the path is not a julia/package install path, its a folder where I test julia packages)

Bridgestan in R (version 2.3.0) errors and returns this: (on an official model, R version 4.2.1)

Operating System: Windows 10

I’m running out of ideas what I could try to resolve the problems! I hope someone here can help.

Hi @Raoul-Kima, this is a reasonable place to ask BridgeStan related questions like this.

Many of the error messages you shared are from Boost or RTools, but not BridgeStan itself.

As I recall, though I could be wrong, Make has problems with filepaths that contain spaces. I don’t have a windows machine though, so I can’t even begin to try to replicate the bigger issues.

@WardBrian, would you mind taking a look at this thread?

The warnings (especially any that mention boost’s usage of unary_function) are unfortunate but safe to ignore here.

Windows has two big caveats for Stan in general:

  1. Make is not happy when there are spaces in file paths. It sounds like you’ve figured this out yourself, which is great
  2. Dynamic libraries can’t be in “fixed” locations like on MacOS or Linux. I suspect this may be the issue here.

If you’re getting a “module not found” error when you know that file exists (and you’re already using an absolute path) the most likely problem is that it can’t find a dependency. Unfortunately Windows doesn’t make any distinction in the error message here.

My guess is either:

  1. BridgeStan’s attempt to tell the operating system where the TBB library is inside of its downloaded folder is failing for some reason. It’s hard to say why this would be, but we can explore it
  2. Another version of TBB is installed in a place with higher priority, and it’s causing issues. The way to check this is to share the output of running where.exe tbb.dll

Thanks for the help!

I’m not quite sure what you mean with “fixed”.

Do you mean the path displayed in Julia error message?

Do you mean like this?:
image

I’ve checked the install instructions for BridgeStan and the c++ toolchain again, and it mentions TBB only in the section “installation from github”. So that shouldn’t apply to my case?
Here’s that section:


I didnt originally do what this section says.
Just to check what happens, I now tried adding “C:\BridgeStan\bridgestan-2.3.0\stan\lib\stan_math\lib\tbb” to my PATH, and this causes Bridgestan in Julia to work correctly. BridgeStan in R still fails, though.
Here’s the error:

and the Code:
image

Should I try removing the PATH entry and running the “mingw32-make install-tbb” command instead? Or would you recommend some aother approach?

On other systems we can bake the location of libraries like TBB into the compiled Stan files, so none of this PATH stuff is necessary.

It is great to hear that manually adding TBB to the PATH worked in Julia. This should have been automatic, but looking at the code now I can see why it was not, and will fix that. And no, there’s no difference between manually adding the TBB folder to your PATH and running the install-tbb command

Is there more to the error in R? It looks like it is failing during compilation rather than during loading, but it is hard to tell from the image you provided

What was supposed to be automatic, the adding to PATH? So it would have been added twice if both the R and Julia interfaces add their own TBB. (I’m a bit confused about that part)
So I should just leave it in PATH? Or is it supposed to work without that after the fix?

This is the only output it gave. I can try to find out more, but am not sure how to approach that. Do you have an idea how/where to start looking?

My RStan and cmdstanR are quite old, but that shouldnt influence it, right?

BridgeStan attempts to automatically and temporarily add TBB to the PATH on Windows. Currently in Julia this is done at startup, which means it doesn’t work correctly if you call set_bridgestan_path later. I just merged a fix for this which will be in our next release.

You should be fine leaving it in the PATH, but in the next version it would also be fine to remove it.

For R, it looks like error messages are cut off at warning.length, so you could try something like

options(warning.length = 5000L)

and see if that gives the complete error message

Then I get this:

That error is strange - it’s the kind of thing I would expect if there were multiple C++ compilers on your system, and a mix of them were being used.

Is one of these (either Julia or R) in a Conda environment? Are you using RTools, or some other source for your C++ compiler?

Could you share the output of this R script

library(bridgestan)
# call set_bridgestan_path HERE if needed
system2("mingw32-make", args = paste0("-C", bridgestan:::get_bridgestan_path())) 

and this Julia one:

using BridgeStan
# call set_bridgestan_path HERE if needed
loc = BridgeStan.get_bridgestan_path()
run(`mingw32-make -C $loc`)

Comparing these two may help us understand why one is working

I’m not knowingly using conda.
I’m not knowingly using anything but RTools as compiler. I do currently have 2 RTools installations though (because I wanted to test whether using a different version solves the problem).
In Environment variables there is this:
image

… and PATH, which contains:
image

I also tested putting rtools43 in PATH instead. As far as I could see (and I looked quite closely). The results are all exactly the same (to the letter) no matter which version is listed there. That is: Julia-Bridgestan works in both cases. R-Bridgestan fails with the same message in both cases, and the two outputs below are also identical in both cases.

What I didnt try yet is to uninstall rtools43 (my R isnt fully up to date, so its still using rtools42. According to the documentation Bridgestan should be compatible with rtools42. There are no version (or other) warnings when loading Bridgestan into R).
Please say if you’d like me to try uninstalling rtools43. I dont need it at the moment, only installed it for these tests (that was before adding the tbb path to PATH, so I havent tested the current config without rtools43 being installed yet.).

Here ist the output that you requested:

The R-script returns this:

MINGW3~1.EXE: Entering directory 'C:/BridgeStan/bridgestan-2.3.0'
  Current configuration:
  - OS (Operating System):       Windows_NT
  - CXX (Compiler):              g++
  - CXX_TYPE                     gcc
  - Compiler version:            10.4
  - O (Optimization Level):      3
  Library configuration:
  - EIGEN                        ./stan/lib/stan_math/lib/eigen_3.4.0
  - BOOST                        ./stan/lib/stan_math/lib/boost_1.78.0
  - SUNDIALS                     ./stan/lib/stan_math/lib/sundials_6.1.1
  - TBB                          ./stan/lib/stan_math/lib/tbb_2020.3
  - GTEST                        ./stan/lib/stan_math/lib/benchmark_1.5.1/googletest/googletest
  - STAN_THREADS                
  - STAN_OPENCL                 
  - STAN_MPI                    
  Compiler flags (each can be overriden separately):
  - CXXFLAGS_LANG                -std=c++1y
  - CXXFLAGS_WARNINGS            -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs -Wno-int-in-bool-context -Wno-attributes -Wno-ignored-attributes
  - CXXFLAGS_OPTIM              
  - CXXFLAGS_FLTO               
  - CXXFLAGS_BOOST              
  - CXXFLAGS_EIGEN              
  - CXXFLAGS_OS                  -m64 -D_REENTRANT
  - CXXFLAGS_GTEST              
  - CXXFLAGS_THREADS            
  - CXXFLAGS_OPENCL             
  - CXXFLAGS_TBB                 -I ./stan/lib/stan_math/lib/tbb_2020.3/include
  - CXXFLAGS_OPTIM_TBB          
  - CXXFLAGS_MPI                
  - CFLAGS_SUNDIALS             
  - CXXFLAGS_SUNDIALS            -pipe -fPIC
  - CXXFLAGS_OPTIM_SUNDIALS     
  LDLIBS:
  - LDLIBS_LANG                 
  - LDLIBS_WARNINGS             
  - LDLIBS_EIGEN                
  - LDLIBS_BOOST                
  - LDLIBS_SUNDIALS             
  - LDLIBS_OS                    -static-libgcc -static-libstdc++
  - LDLIBS_GTEST                
  - LDLIBS_OPENCL               
  - LDLIBS_TBB                   -Wl,-L,C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb -Wl,-rpath,C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb
  - LDLIBS_MPI                  
  LDFLAGS:
  - LDFLAGS_LANG                
  - LDFLAGS_WARNINGS            
  - LDFLAGS_EIGEN               
  - LDFLAGS_BOOST               
  - LDFLAGS_SUNDIALS            
  - LDFLAGS_OS                  
  - LDFLAGS_GTEST               
  - LDFLAGS_OPENCL              
  - LDFLAGS_TBB                  -Wl,-L,C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb -Wl,-rpath,C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb
  - LDFLAGS_MPI                 

MINGW3~1.EXE: Leaving directory 'C:/BridgeStan/bridgestan-2.3.0'

The Julia script returns this:

mingw32-make: Entering directory 'C:/BridgeStan/bridgestan-2.3.0'
  Current configuration:
  - OS (Operating System):       Windows_NT
  - CXX (Compiler):              g++
  - CXX_TYPE                     gcc
  - Compiler version:            13.2
  - O (Optimization Level):      3
  Library configuration:
  - EIGEN                        ./stan/lib/stan_math/lib/eigen_3.4.0
  - BOOST                        ./stan/lib/stan_math/lib/boost_1.78.0
  - SUNDIALS                     ./stan/lib/stan_math/lib/sundials_6.1.1
  - TBB                          ./stan/lib/stan_math/lib/tbb_2020.3
  - GTEST                        ./stan/lib/stan_math/lib/benchmark_1.5.1/googletest/googletest
  - STAN_THREADS
  - STAN_OPENCL
  - STAN_MPI
  Compiler flags (each can be overriden separately):
  - CXXFLAGS_LANG                -std=c++1y
  - CXXFLAGS_WARNINGS            -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs -Wno-int-in-bool-context -Wno-attributes -Wno-ignored-attributes
  - CXXFLAGS_OPTIM
  - CXXFLAGS_FLTO
  - CXXFLAGS_BOOST
  - CXXFLAGS_EIGEN
  - CXXFLAGS_OS                  -m64 -D_REENTRANT
  - CXXFLAGS_GTEST
  - CXXFLAGS_THREADS
  - CXXFLAGS_OPENCL
  - CXXFLAGS_TBB                 -I ./stan/lib/stan_math/lib/tbb_2020.3/include
  - CXXFLAGS_OPTIM_TBB
  - CXXFLAGS_MPI
  - CFLAGS_SUNDIALS
  - CXXFLAGS_SUNDIALS            -pipe -fPIC
  - CXXFLAGS_OPTIM_SUNDIALS     
  LDLIBS:
  - LDLIBS_LANG
  - LDLIBS_WARNINGS
  - LDLIBS_EIGEN
  - LDLIBS_BOOST
  - LDLIBS_SUNDIALS
  - LDLIBS_OS                    -static-libgcc -static-libstdc++
  - LDLIBS_GTEST
  - LDLIBS_OPENCL
  - LDLIBS_TBB                   -Wl,-L,C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb -Wl,-rpath,C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb
  - LDLIBS_MPI
  LDFLAGS:
  - LDFLAGS_LANG
  - LDFLAGS_WARNINGS
  - LDFLAGS_EIGEN
  - LDFLAGS_BOOST
  - LDFLAGS_SUNDIALS
  - LDFLAGS_OS
  - LDFLAGS_GTEST
  - LDFLAGS_OPENCL
  - LDFLAGS_TBB                  -Wl,-L,C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb -Wl,-rpath,C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb
  - LDFLAGS_MPI

mingw32-make: Leaving directory 'C:/BridgeStan/bridgestan-2.3.0'
Process(`mingw32-make -C 'C:\BridgeStan\bridgestan-2.3.0'`, ProcessExited(0))

Ah, the GCC version is different in R, and it matches the one I would expect from RTools43. My guess is R is setting PATH to point to the one matching the R version (I assume you’re using R 4.3, not 4.2?)

I would try setting your path to the rtools43 instead, and then deleting the bridgrstan folder and trying to build it from a clean download

No,
it’s R version 4.2.1. I’m not entirely sure whether rtools43 was already present on the system when I installed R-bridgestan. I’ll try uninstalling RTools43 (or maybe just removing its environment variable) and reinstalling bridgestan.

New test, still problems.
What I did, in this order:

  • Made sure PATH and other windows environment variables (both on the user level and system level) all point to RTools42 and there are no more mentions of RTools43 .
  • Removed RTools43 with its uninstaller. (As I’m using R 4.2.1)
  • Made sure the RTools deinstaller completely removed the RTools43 folder.
  • Removed the bridgestan folder from the renv folder in the RStudio project which I am using to test bridgestan.
  • Removed folder C:\BridgeStan\bridgestan-2.3.0 (this is the bridgestan installation that I point R and julia to because their own installations have spaces in the path)
  • Recreated C:\BridgeStan\bridgestan-2.3.0 by unpacking bridgestan-2.3.0.tar.gz from Releases · roualdes/bridgestan · GitHub
  • Rebooted the computer.
  • Reinstalled bridgestan in the test R-project by installing it from the sources contained in C:\BridgeStan\bridgestan-2.3.0\R
    (The r-code for the install was: install.packages(file.path("C:/BridgeStan/bridgestan-2.3.0","R"), repos=NULL, type="source") ).

Trying to compile a model through bridgestan in R now gives this:

Error in compile_model(lib, stanc_args, make_args) : 
  Compilation failed with error code 2
output:
MINGW3~1.EXE: Entering directory 'C:/BridgeStan/bridgestan-2.3.0'
curl -L https://github.com/stan-dev/stanc3/releases/download/v2.33.1/windows-stanc -o ./bin/stanc.exe --retry 5 --retry-delay 10
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 22.3M  100 22.3M    0     0  2006k      0  0:00:11  0:00:11 --:--:-- 2161k

--- Compiling Stan bridge C++ code ---
g++ -std=c++1y -m64 -D_REENTRANT -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs -Wno-int-in-bool-context -Wno-attributes -Wno-ignored-attributes      -I ./stan/lib/stan_math/lib/tbb_2020.3/include    -O3 -I ./stan/src -I ./stan/lib/rapidjson_1.1.0/ -I ./stan/lib/stan_math/ -I ./stan/lib/stan_math/lib/eigen_3.4.0 -I ./stan/lib/stan_math/lib/boost_1.78.0 -I ./stan/lib/stan_math/lib/sundials_6.1.1/include -I ./stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -fPIC -fvisibility=hidden -fvisibility-inlines-hidden  -D_USE_MATH_DEFINES  -DBOOST_DISABLE_ASSERTS         -DBRIDGESTAN_EXPORT  -c -o src/bridgestan.o  -static-libgcc -static-libstdc++     -Wl,-L,"C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb"     src/bridgestan.cpp
g++ -pipe   -fPIC -m64 -D_REENTRANT  -O3 -I ./stan/lib/stan_math/lib/sundials_6.1.1/include -I ./stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -DNO_FPRINTF_OUTPUT   -D_USE_MATH_DEFINES  -O3  -c -x c -include ./stan/lib/stan_math/lib/sundials_6.1.1/include/stan_sundials_printf_override.hpp stan/lib/stan_math/lib/sundials_6.1.1/src/nvector/serial/nvector_serial.c -o stan/lib/stan_math/lib/sundials_6.1.1/src/nvector/serial/nvector_serial.o
g++ -pipe   -fPIC -m64 -D_REENTRANT  -O3 -I ./stan/lib/stan_math/lib/sundials_6.1.1/include -I ./stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -DNO_FPRINTF_OUTPUT   -D_USE_MATH_DEFINES  -O3  -c -x c -include ./stan/lib/stan_math/lib/sundials_6.1.1/include/stan_sundials_printf_override.hpp stan/lib/stan_math/lib/sundials_6.1.1/src/sundials/sundials_math.c -o stan/lib/stan_math/lib/sundials_6.1.1/src/sundials/sundials_math.o
ar -rs stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_nvecserial.a stan/lib/stan_math/lib/sundials_6.1.1/src/nvector/serial/nvector_serial.o stan/lib/stan_math/lib/sundials_6.1.1/src/sundials/sundials_math.o
ar: creating stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_nvecserial.a
g++ -pipe   -fPIC -m64 -D_REENTRANT  -O3 -I ./stan/lib/stan_math/lib/sundials_6.1.1/include -I ./stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -DNO_FPRINTF_OUTPUT   -D_USE_MATH_DEFINES  -O3  -c -x c -include ./stan/lib/stan_math/lib/sundials_6.1.1/include/stan_sundials_printf_override.hpp stan/lib/stan_math/lib/sundials_6.1.1/src/cvodes/cvodea.c -o stan/lib/stan_math/lib/sundials_6.1.1/src/cvodes/cvodea.o
g++ -pipe   -fPIC -m64 -D_REENTRANT  -O3 -I ./stan/lib/stan_math/lib/sundials_6.1.1/include -I ./stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -DNO_FPRINTF_OUTPUT   -D_USE_MATH_DEFINES  -O3  -c -x c -include ./stan/lib/stan_math/lib/sundials_6.1.1/include/stan_sundials_printf_override.hpp stan/lib/stan_math/lib/sundials_6.1.1/src/cvodes/cvodea_io.c -o stan/lib/stan_math/lib/sundials_6.1.1/src/cvodes/cvodea_io.o
g++ -pipe   -fPIC -m64 -D_REENTRANT  -O3 -I ./stan/lib/stan_math/lib/sundials_6.1.1/include -I ./stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -DNO_FPRINTF_OUTPUT   -D_USE_MATH_DEFINES  -O3  -c -x c -include ./stan/lib/stan_math/lib/sundials_6.1.1/include/stan_sundials_printf_override.hpp stan/lib/stan_math/lib/sundials_6.1.1/src/cvodes/cvodes.c -o stan/lib/stan_math/lib/sundials_6.1.1/src/cvodes/cvodes.o
g++ -pipe   -fPIC -m64 -D_REENTRANT  -O3 -I ./stan/lib/stan_math/lib/sundials_6.1.1/include -I ./stan/lib/stan_math/l

calling system2("mingw32-make", args = paste0("-C", bridgestan:::get_bridgestan_path())) in R returns this:

MINGW3~1.EXE: Entering directory 'C:/BridgeStan/bridgestan-2.3.0'
  Current configuration:
  - OS (Operating System):       Windows_NT
  - CXX (Compiler):              g++
  - CXX_TYPE                     gcc
  - Compiler version:            10.4
  - O (Optimization Level):      3
  Library configuration:
  - EIGEN                        ./stan/lib/stan_math/lib/eigen_3.4.0
  - BOOST                        ./stan/lib/stan_math/lib/boost_1.78.0
  - SUNDIALS                     ./stan/lib/stan_math/lib/sundials_6.1.1
  - TBB                          ./stan/lib/stan_math/lib/tbb_2020.3
  - GTEST                        ./stan/lib/stan_math/lib/benchmark_1.5.1/googletest/googletest
  - STAN_THREADS                
  - STAN_OPENCL                 
  - STAN_MPI                    
  Compiler flags (each can be overriden separately):
  - CXXFLAGS_LANG                -std=c++1y
  - CXXFLAGS_WARNINGS            -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs -Wno-int-in-bool-context -Wno-attributes -Wno-ignored-attributes
  - CXXFLAGS_OPTIM              
  - CXXFLAGS_FLTO               
  - CXXFLAGS_BOOST              
  - CXXFLAGS_EIGEN              
  - CXXFLAGS_OS                  -m64 -D_REENTRANT
  - CXXFLAGS_GTEST              
  - CXXFLAGS_THREADS            
  - CXXFLAGS_OPENCL             
  - CXXFLAGS_TBB                 -I ./stan/lib/stan_math/lib/tbb_2020.3/include
  - CXXFLAGS_OPTIM_TBB          
  - CXXFLAGS_MPI                
  - CFLAGS_SUNDIALS             
  - CXXFLAGS_SUNDIALS            -pipe -fPIC
  - CXXFLAGS_OPTIM_SUNDIALS     
  LDLIBS:
  - LDLIBS_LANG                 
  - LDLIBS_WARNINGS             
  - LDLIBS_EIGEN                
  - LDLIBS_BOOST                
  - LDLIBS_SUNDIALS             
  - LDLIBS_OS                    -static-libgcc -static-libstdc++
  - LDLIBS_GTEST                
  - LDLIBS_OPENCL               
  - LDLIBS_TBB                   -Wl,-L,C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb -Wl,-rpath,C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb
  - LDLIBS_MPI                  
  LDFLAGS:
  - LDFLAGS_LANG                
  - LDFLAGS_WARNINGS            
  - LDFLAGS_EIGEN               
  - LDFLAGS_BOOST               
  - LDFLAGS_SUNDIALS            
  - LDFLAGS_OS                  
  - LDFLAGS_GTEST               
  - LDFLAGS_OPENCL              
  - LDFLAGS_TBB                  -Wl,-L,C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb -Wl,-rpath,C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb
  - LDFLAGS_MPI                 

MINGW3~1.EXE: Leaving directory 'C:/BridgeStan/bridgestan-2.3.0'

Bridgestan in Julia still works.
Here what Julia sais about the current setup:

mingw32-make: Entering directory 'C:/BridgeStan/bridgestan-2.3.0'
  Current configuration:
  - OS (Operating System):       Windows_NT
  - CXX (Compiler):              g++
  - CXX_TYPE                     gcc
  - Compiler version:            13.2
  - O (Optimization Level):      3
  Library configuration:
  - EIGEN                        ./stan/lib/stan_math/lib/eigen_3.4.0
  - BOOST                        ./stan/lib/stan_math/lib/boost_1.78.0
  - SUNDIALS                     ./stan/lib/stan_math/lib/sundials_6.1.1
  - TBB                          ./stan/lib/stan_math/lib/tbb_2020.3
  - GTEST                        ./stan/lib/stan_math/lib/benchmark_1.5.1/googletest/googletest
  - STAN_THREADS
  - STAN_OPENCL
  - STAN_MPI
  Compiler flags (each can be overriden separately):
  - CXXFLAGS_LANG                -std=c++1y
  - CXXFLAGS_WARNINGS            -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs -Wno-int-in-bool-context -Wno-attributes -Wno-ignored-attributes
  - CXXFLAGS_OPTIM
  - CXXFLAGS_FLTO
  - CXXFLAGS_BOOST
  - CXXFLAGS_EIGEN
  - CXXFLAGS_OS                  -m64 -D_REENTRANT
  - CXXFLAGS_GTEST
  - CXXFLAGS_THREADS
  - CXXFLAGS_OPENCL
  - CXXFLAGS_TBB                 -I ./stan/lib/stan_math/lib/tbb_2020.3/include
  - CXXFLAGS_OPTIM_TBB
  - CXXFLAGS_MPI
  - CFLAGS_SUNDIALS
  - CXXFLAGS_SUNDIALS            -pipe -fPIC
  - CXXFLAGS_OPTIM_SUNDIALS     
  LDLIBS:
  - LDLIBS_LANG
  - LDLIBS_WARNINGS
  - LDLIBS_EIGEN
  - LDLIBS_BOOST
  - LDLIBS_SUNDIALS
  - LDLIBS_OS                    -static-libgcc -static-libstdc++
  - LDLIBS_GTEST
  - LDLIBS_OPENCL
  - LDLIBS_TBB                   -Wl,-L,C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb -Wl,-rpath,C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb
  - LDLIBS_MPI
  LDFLAGS:
  - LDFLAGS_LANG
  - LDFLAGS_WARNINGS
  - LDFLAGS_EIGEN
  - LDFLAGS_BOOST
  - LDFLAGS_SUNDIALS
  - LDFLAGS_OS
  - LDFLAGS_GTEST
  - LDFLAGS_OPENCL
  - LDFLAGS_TBB                  -Wl,-L,C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb -Wl,-rpath,C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb
  - LDFLAGS_MPI

mingw32-make: Leaving directory 'C:/BridgeStan/bridgestan-2.3.0'
Process(`mingw32-make -C 'C:\BridgeStan\bridgestan-2.3.0'`, ProcessExited(0))

I notice both are still returning the same compiler verion number. Above you said that the version of R is what you would expect from RTools43. But RTools43 is no longer present on my system. I wonder where Julia has its version from, as that is a newer version then the one from R. Might there be another compiler somewhere that I’m not aware of?

It sounds like there probably is another compiler.

One thing you could try is having a separate bridgestan folder for R and Julia, so two compilers wouldn’t be as big a deal, but that is obviously just working around whatever is actually happening.

In Julia, you can try

println(get(ENV, "CXX", "not set"))
run(`where.exe g++`)

This should hopefully tell us where the other compiler is coming from.

I’m not sure that would help, because I never used the new bridgestan Install with Julia before executing the R-test, yet the test failed.

It returns:

not set 

C:\rtools42\ucrt64\bin\g++.exe
Process(`where.exe g++`, ProcessExited(0))

When I run system("where.exe g++") in R I get:

C:\rtools42\x86_64-w64-mingw32.static.posix\bin\g++.exe
C:\rtools42\ucrt64\bin\g++.exe

When I Run Sys.getenv() in R I find these entries amongst the returns:

R_RTOOLS42_PATH                      C:\rtools42/x86_64-w64-mingw32.static.posix/bin;C:\rtools42/usr/bin
PATH                                 C:\rtools42/x86_64-w64-mingw32.static.posix/bin;C:\rtools42/usr/bin;C:\Program
                                     Files\R\R-4.2.1\bin\x64;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program
                                     Files (x86)\AOMEI\AOMEI Backupper\6.9.2;C:\Program Files\Microsoft VS
                                     Code\bin;C:\Program Files\dotnet\;C:\Program Files\Git\cmd;C:\Users\Raoul
                                     Kima\AppData\Local\Microsoft\WindowsApps;C:\Users\Raoul
                                     Kima\AppData\Local\gitkraken\bin;C:\Users\Raoul
                                     Kima\AppData\Local\Programs\Julia-1.10.0\bin;C:\rtools42\usr\bin;C:\rtools42\ucrt64\bin;C:\BridgeStan\bridgestan-2.3.0\stan\lib\stan_math\lib\tbb;;C:/Program Files/RStudio/bin/quarto/bin

This looks suspicious to me as it mentiones C:\rtools42/x86_64-w64-mingw32.static.posix/bin !
But this doesnt’t come from windows PATH variable.
Renviron or Rprofile file could affect these environment variables. So I checked if it comes from them.
I didnt find any .Renviron or .Renviron.site files in any of the locations mentioned in https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/Startup
Existing Rprofile and Rprofile.site files didnt have any suspicious entries.

I also looked at other files mentioning C:\rtools42/x86_64-w64-mingw32.static.posix/bin. But at this point I’m fishing in places that I dont know much about.
The file C:\Program Files\R\R-4.2.1\etc\x64\Makeconf mentions the location several times.
In File C:\Program Files\R\R-4.2.1\etc\Rcmd_environ I found this entry:

R_RTOOLS42_PATH="${RTOOLS42_HOME:-c:/rtools42}/x86_64-w64-mingw32.static.posix/bin;${RTOOLS42_HOME:-c:/rtools42}/usr/bin"

Just to test the effect I changed the latter file (removed the first part of the path) and restarted RStudio, but that had no effect on the two suspicious entries in Sys.getenv(). However, the behaviour of Bridgestan has changed: When I run it I now get R encountered a fatal error. The session was terminated. Changing the Rcmd_environ file back to its previous state didn’t change the behaviour of Bridgestan back, so im not sure whether that is related. (but I’m not aware of having changed anything else since the last Bridgestan test in R). Removing bridgestan from the renv folder and reinstalling it (same method as in previous post) also didnt resolve the crash. Deleting my bridgestan folder and remaking it (same method as in previous post), then reinstalling the r-package, brought back the previous bridgestan behaviour (compile-error without R-crash).

At this point I have no further ideas where the C:\rtools42/x86_64-w64-mingw32.static.posix/bin in Sys.getenv() might be coming from.

When I use Sys.setenv(PATH= to remove just that one entry, then Bridgestan returns this error:

Error in compile_model(lib, stanc_args, make_args) : 
  Compilation failed with error code 2
output:
MINGW3~1.EXE: Entering directory 'C:/BridgeStan/bridgestan-2.3.0'
if ! [[ C:/rtools42/ucrt64/bin/MINGW3~1.EXE =~ mingw32 ]]; then \
	echo "ERROR: Please use mingw32-make on Windows to build the Intel TBB library."; \
	echo "This is packaged with RTools, for example."; \
	exit 1; \
fi
ERROR: Please use mingw32-make on Windows to build the Intel TBB library.
This is packaged with RTools, for example.
MINGW3~1.EXE: *** [stan/lib/stan_math/make/libraries:155: stan/lib/stan_math/lib/tbb/tbb-make-check] Error 1
MINGW3~1.EXE: Leaving directory 'C:/BridgeStan/bridgestan-2.3.0'

I’ll stop here as I feel that I’m just fishing in the dark at this point. This is outside my expertise. Hopefully you can make more sense of this.

A sidenote: I also discovered that there is a folder C:\Users\Raoul Kima\Documents\.bridgestan\bridgestan-2.3.0 that I wasnt previously aware of. Is that the bridgestan installation used by R if i dont use set_bridgestan_path() ?

update:
getting it back from the “please install TBB” error to the previous one again required reinstalling bridgestan. So I thought why not try what happens when I run that same test (removing the first entry of PATH via sys.getenv()) on a fresh bridgestan install.
It returns this:

Error in compile_model(lib, stanc_args, make_args) : 
  Compilation failed with error code 2
output:
MINGW3~1.EXE: Entering directory 'C:/BridgeStan/bridgestan-2.3.0'
curl -L https://github.com/stan-dev/stanc3/releases/download/v2.33.1/windows-stanc -o ./bin/stanc.exe --retry 5 --retry-delay 10
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 22.3M  100 22.3M    0     0  2012k      0  0:00:11  0:00:11 --:--:-- 2169k

--- Compiling Stan bridge C++ code ---
g++ -std=c++1y -m64 -D_REENTRANT -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs -Wno-int-in-bool-context -Wno-attributes -Wno-ignored-attributes      -I ./stan/lib/stan_math/lib/tbb_2020.3/include    -O3 -I ./stan/src -I ./stan/lib/rapidjson_1.1.0/ -I ./stan/lib/stan_math/ -I ./stan/lib/stan_math/lib/eigen_3.4.0 -I ./stan/lib/stan_math/lib/boost_1.78.0 -I ./stan/lib/stan_math/lib/sundials_6.1.1/include -I ./stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -fPIC -fvisibility=hidden -fvisibility-inlines-hidden  -D_USE_MATH_DEFINES  -DBOOST_DISABLE_ASSERTS         -DBRIDGESTAN_EXPORT  -c -o src/bridgestan.o  -static-libgcc -static-libstdc++     -Wl,-L,"C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"C:/BridgeStan/bridgestan-2.3.0/stan/lib/stan_math/lib/tbb"     src/bridgestan.cpp
In file included from ./stan/lib/stan_math/lib/boost_1.78.0/boost/multi_array/multi_array_ref.hpp:32,
                 from ./stan/lib/stan_math/lib/boost_1.78.0/boost/multi_array.hpp:34,
                 from ./stan/lib/stan_math/lib/boost_1.78.0/boost/numeric/odeint/algebra/multi_array_algebra.hpp:22,
                 from ./stan/lib/stan_math/lib/boost_1.78.0/boost/numeric/odeint.hpp:63,
                 from ./stan/lib/stan_math/stan/math/prim/functor/ode_rk45.hpp:9,
                 from ./stan/lib/stan_math/stan/math/prim/functor/integrate_ode_rk45.hpp:6,
                 from ./stan/lib/stan_math/stan/math/prim/functor.hpp:16,
                 from ./stan/lib/stan_math/stan/math/rev/fun.hpp:200,
                 from ./stan/lib/stan_math/stan/math/rev.hpp:10,
                 from ./stan/lib/stan_math/stan/math.hpp:19,
                 from src/model_rng.cpp:9,
                 from src/bridgestan.cpp:2:
./stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:180:45: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  180 |         : public boost::functional::detail::unary_function<typename unary_traits<Predicate>::argument_type,bool>
      |                                             ^~~~~~~~~~~~~~
In file included from C:/rtools42/ucrt64/include/c++/13.2.0/string:49,
                 from C:/rtools42/ucrt64/include/c++/13.2.0/bits/locale_classes.h:40,
                 from C:/rtools42/ucrt64/include/c++/13.2.0/bits/ios_base.h:41,
                 from C:/rtools42/ucrt64/include/c++/13.2.0/ios:44,
                 from C:/rtools42/ucrt64/include/c++/13.2.0/istream:40,
                 from C:/rtools42/ucrt64/include/c++/13.2.0/sstream:40,
                 from ./stan/src/stan/io/var_context.hpp:4,
                 from ./stan/src/stan/model/model_base.hpp:4,
                 from src/model_rng.hpp:4,
                 from src/bridgestan.h:7,
                 from src/bridgestan.cpp:1:
C:/rtools42/ucrt64/include/c++/13.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
./stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:214:45: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  214 |         : public boost::functional::detail::binary_function<
      |                                             ^~~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/13.2.0/bits/stl_functi

The last line looks a bit cut off, so I increased the error printing limit again, and tried to compile again. Strangely, this gave a different error:

Error in compile_model(lib, stanc_args, make_args) : 
  Compilation failed with error code 2
output:
MINGW3~1.EXE: Entering directory 'C:/BridgeStan/bridgestan-2.3.0'
if ! [[ C:/rtools42/ucrt64/bin/MINGW3~1.EXE =~ mingw32 ]]; then \
	echo "ERROR: Please use mingw32-make on Windows to build the Intel TBB library."; \
	echo "This is packaged with RTools, for example."; \
	exit 1; \
fi
ERROR: Please use mingw32-make on Windows to build the Intel TBB library.
This is packaged with RTools, for example.
MINGW3~1.EXE: *** [stan/lib/stan_math/make/libraries:155: stan/lib/stan_math/lib/tbb/tbb-make-check] Error 1
MINGW3~1.EXE: Leaving directory 'C:/BridgeStan/bridgestan-2.3.0'

Afterwards I set everything back to how we had it before (as far as I could tell), checking twice what error it gives. The first error looked as expected at first glance. But on the second try It again gave the “install tbb”. Strange, it didnt to that before todays series of tests.

… also I wonder why rstan and cmdstanr worked fine when I tested them, while bridgestan didnt.

I’m also not sure. The fact that you have Julia working means it is something very R-environment-specific, which is unfortunately not an area I have that much experience with