Error installing CmdStan, invalid conversion from 'const'

I’m trying to install CmdStan but I can’t compile the Bernoulli example. The issue seems to be described in the following lines:

stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/Core/Map.h:142:31: note:   initializing argument 1 of 'Eigen::Map<MatrixType, MapOptions, StrideType>::Map(Eigen::Map<MatrixType, MapOptions, StrideType>::PointerArgType, Eigen::Index, const StrideType&) [with PlainObjectType = Eigen::Matrix<double, -1, 1>; int MapOptions = 0; StrideType = Eigen::Stride<0, 0>; Eigen::Map<MatrixType, MapOptions, StrideType>::PointerArgType = double*; Eigen::Index = long long int]'
stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/Core/Map.h:142:31: note:   initializing argument 1 of 'Eigen::Map<MatrixType, MapOptions, StrideType>::Map(Eigen::Map<MatrixType, MapOptions, StrideType>::PointerArgType, Eigen::Index, const StrideType&) [with PlainObjectType = Eigen::Matrix<int, -1, 1>; int MapOptions = 0; StrideType = Eigen::Stride<0, 0>; Eigen::Map<MatrixType, MapOptions, StrideType>::PointerArgType = int*; Eigen::Index = long long int]'

Not sure what’s going on! I’m out of ideas.

Here’s exactly the code I used to generate this error:

Microsoft Windows [Version 10.0.17763.4131]
(c) 2018 Microsoft Corporation. All rights reserved.

U:\>C:

C:\>cd Users\ter58_RS\cmdstan

C:\Users\ter58_RS\cmdstan>mingw32-make build

NOTE: Please add C:/Users/ter58_RS/cmdstan/stan/lib/stan_math/lib/tbb to your PATH variable.
You may call

mingw32-make install-tbb

to automatically update your user configuration.
--- CmdStan v2.31.0 built ---

C:\Users\ter58_RS\cmdstan>mingw32-make install-tbb
cmd.exe /C install-tbb.bat
Permanently setting the PATH user environment variable:

SUCCESS: Specified value was saved.
Please close this shell and open a new shell.
This will make the changes to the PATH variable
become active.

C:\Users\ter58_RS\cmdstan>mingw32-make examples/bernoulli/bernoulli.exe

--- Compiling, linking C++ code ---
g++ -Wno-nonnull -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 src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -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  -D_USE_MATH_DEFINES  -DBOOST_DISABLE_ASSERTS          -c -Wno-ignored-attributes   -x c++ -o examples/bernoulli/bernoulli.o examples/bernoulli/bernoulli.hpp
In file included from stan/src/stan/model/model_header.hpp:8:
stan/src/stan/io/deserializer.hpp: In instantiation of 'stan::io::deserializer<T>::deserializer(RVec&, IntVec&) [with RVec = const std::vector<double, std::allocator<double> >; IntVec = const std::vector<int>; stan::require_all_vector_like_t<RVec, IntVec>* <anonymous> = 0; T = double]':
examples/bernoulli/bernoulli.hpp:163:46:   required from 'void bernoulli_model_namespace::bernoulli_model::unconstrain_array_impl(const VecVar&, const VecI&, VecVar&, std::ostream*) const [with VecVar = std::vector<double, std::allocator<double> >; VecI = std::vector<int>; stan::require_vector_t<T_y>* <anonymous> = 0; stan::require_vector_like_vt<std::is_integral, VecI>* <anonymous> = 0; std::ostream = std::basic_ostream<char>]'
examples/bernoulli/bernoulli.hpp:306:36:   required from here
stan/src/stan/io/deserializer.hpp:120:30: error: invalid conversion from 'const double*' to 'Eigen::Map<Eigen::Matrix<double, -1, 1>, 0, Eigen::Stride<0, 0> >::PointerArgType' {aka 'double*'} [-fpermissive]
         i_size_(data_i.size()) {}
                              ^
In file included from stan/lib/stan_math/lib/eigen_3.4.0/Eigen/Core:308,
                 from stan/lib/stan_math/lib/eigen_3.4.0/Eigen/Dense:1,
                 from stan/lib/stan_math/stan/math/prim/fun/Eigen.hpp:22,
                 from stan/lib/stan_math/stan/math/rev.hpp:4,
                 from stan/lib/stan_math/stan/math.hpp:19,
                 from stan/src/stan/model/model_header.hpp:4:
stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/Core/Map.h:142:31: note:   initializing argument 1 of 'Eigen::Map<MatrixType, MapOptions, StrideType>::Map(Eigen::Map<MatrixType, MapOptions, StrideType>::PointerArgType, Eigen::Index, const StrideType&) [with PlainObjectType = Eigen::Matrix<double, -1, 1>; int MapOptions = 0; StrideType = Eigen::Stride<0, 0>; Eigen::Map<MatrixType, MapOptions, StrideType>::PointerArgType = double*; Eigen::Index = long long int]'
     inline Map(PointerArgType dataPtr, Index size, const StrideType& stride = StrideType())
                ~~~~~~~~~~~~~~~^~~~~~~
In file included from stan/src/stan/model/model_header.hpp:8:
stan/src/stan/io/deserializer.hpp:120:30: error: invalid conversion from 'const int*' to 'Eigen::Map<Eigen::Matrix<int, -1, 1>, 0, Eigen::Stride<0, 0> >::PointerArgType' {aka 'int*'} [-fpermissive]
         i_size_(data_i.size()) {}
                              ^
In file included from stan/lib/stan_math/lib/eigen_3.4.0/Eigen/Core:308,
                 from stan/lib/stan_math/lib/eigen_3.4.0/Eigen/Dense:1,
                 from stan/lib/stan_math/stan/math/prim/fun/Eigen.hpp:22,
                 from stan/lib/stan_math/stan/math/rev.hpp:4,
                 from stan/lib/stan_math/stan/math.hpp:19,
                 from stan/src/stan/model/model_header.hpp:4:
stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/Core/Map.h:142:31: note:   initializing argument 1 of 'Eigen::Map<MatrixType, MapOptions, StrideType>::Map(Eigen::Map<MatrixType, MapOptions, StrideType>::PointerArgType, Eigen::Index, const StrideType&) [with PlainObjectType = Eigen::Matrix<int, -1, 1>; int MapOptions = 0; StrideType = Eigen::Stride<0, 0>; Eigen::Map<MatrixType, MapOptions, StrideType>::PointerArgType = int*; Eigen::Index = long long int]'
     inline Map(PointerArgType dataPtr, Index size, const StrideType& stride = StrideType())
                ~~~~~~~~~~~~~~~^~~~~~~
In file included from stan/src/stan/model/model_header.hpp:8:
stan/src/stan/io/deserializer.hpp: In instantiation of 'stan::io::deserializer<T>::deserializer(RVec&, IntVec&) [with RVec = const Eigen::Matrix<double, -1, 1>; IntVec = const std::vector<int>; stan::require_all_vector_like_t<RVec, IntVec>* <anonymous> = 0; T = double]':
examples/bernoulli/bernoulli.hpp:163:46:   required from 'void bernoulli_model_namespace::bernoulli_model::unconstrain_array_impl(const VecVar&, const VecI&, VecVar&, std::ostream*) const [with VecVar = Eigen::Matrix<double, -1, 1>; VecI = std::vector<int>; stan::require_vector_t<T_y>* <anonymous> = 0; stan::require_vector_like_vt<std::is_integral, VecI>* <anonymous> = 0; std::ostream = std::basic_ostream<char>]'
examples/bernoulli/bernoulli.hpp:316:36:   required from here
stan/src/stan/io/deserializer.hpp:120:30: error: invalid conversion from 'const Scalar*' {aka 'const double*'} to 'Eigen::Map<Eigen::Matrix<double, -1, 1>, 0, Eigen::Stride<0, 0> >::PointerArgType' {aka 'double*'} [-fpermissive]
         i_size_(data_i.size()) {}
                              ^
In file included from stan/lib/stan_math/lib/eigen_3.4.0/Eigen/Core:308,
                 from stan/lib/stan_math/lib/eigen_3.4.0/Eigen/Dense:1,
                 from stan/lib/stan_math/stan/math/prim/fun/Eigen.hpp:22,
                 from stan/lib/stan_math/stan/math/rev.hpp:4,
                 from stan/lib/stan_math/stan/math.hpp:19,
                 from stan/src/stan/model/model_header.hpp:4:
stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/Core/Map.h:142:31: note:   initializing argument 1 of 'Eigen::Map<MatrixType, MapOptions, StrideType>::Map(Eigen::Map<MatrixType, MapOptions, StrideType>::PointerArgType, Eigen::Index, const StrideType&) [with PlainObjectType = Eigen::Matrix<double, -1, 1>; int MapOptions = 0; StrideType = Eigen::Stride<0, 0>; Eigen::Map<MatrixType, MapOptions, StrideType>::PointerArgType = double*; Eigen::Index = long long int]'
     inline Map(PointerArgType dataPtr, Index size, const StrideType& stride = StrideType())
                ~~~~~~~~~~~~~~~^~~~~~~
In file included from stan/src/stan/model/model_header.hpp:8:
stan/src/stan/io/deserializer.hpp:120:30: error: invalid conversion from 'const int*' to 'Eigen::Map<Eigen::Matrix<int, -1, 1>, 0, Eigen::Stride<0, 0> >::PointerArgType' {aka 'int*'} [-fpermissive]
         i_size_(data_i.size()) {}
                              ^
In file included from stan/lib/stan_math/lib/eigen_3.4.0/Eigen/Core:308,
                 from stan/lib/stan_math/lib/eigen_3.4.0/Eigen/Dense:1,
                 from stan/lib/stan_math/stan/math/prim/fun/Eigen.hpp:22,
                 from stan/lib/stan_math/stan/math/rev.hpp:4,
                 from stan/lib/stan_math/stan/math.hpp:19,
                 from stan/src/stan/model/model_header.hpp:4:
stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/Core/Map.h:142:31: note:   initializing argument 1 of 'Eigen::Map<MatrixType, MapOptions, StrideType>::Map(Eigen::Map<MatrixType, MapOptions, StrideType>::PointerArgType, Eigen::Index, const StrideType&) [with PlainObjectType = Eigen::Matrix<int, -1, 1>; int MapOptions = 0; StrideType = Eigen::Stride<0, 0>; Eigen::Map<MatrixType, MapOptions, StrideType>::PointerArgType = int*; Eigen::Index = long long int]'
     inline Map(PointerArgType dataPtr, Index size, const StrideType& stride = StrideType())
                ~~~~~~~~~~~~~~~^~~~~~~
mingw32-make: *** [make/program:58: examples/bernoulli/bernoulli.exe] Error 1

What do you get from: g++ --version?

Also, are you using a custom combination/build of cmdstan? Your output refers to cmdstan-2.31.0, but the include flags mention eigen_3.4.0, which wasn’t the version in 2.31.0

I get 8.3.0:

U:\>g++ --version
g++ (Built by Jeroen for the R-project) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I am not using a custom build of CmdStan. Maybe there’s some kind of conflict with a previous installation?

Also, I tried doing this and I got these error messages:

image

image

Thanks!

Can you try downloading the latest release from the release page and then try again?

That worked! Should’ve tried to do that before posting this. Thanks a lot.

Actually, when I try to compile my model and not the example Bernoulli one I still get the xxx.dll error messages. Any idea how I could fix that?

The same mp ones or a tbb one?

These ones:

image

Those are a bit strange. First thing to check, can you compile basic c++:

echo int main() { return 0; } > foo.cpp
g++ foo.cpp

You might also have some PATH issues, what’s the output from:

echo $PATH

Here’s the output. Seems like it’s OK?

U:\>echo int main() { return 0; } > foo.cpp

U:\>g++ foo.cpp

U:\>echo $PATH
$PATH

U:\>

foo.cpp was created in the directory.

(Is this what I was supposed to do? Sorry, C++ is not a language I know a lot about.)

Ah sorry, forgot you were using command prompt, the right command is:

echo %PATH%
C:\rtools42\usr\bin;
C:\rtools42\mingw64\bin;
C:\Users\ter58_RS;
C:\Program Files\Python39\Scripts\;
C:\Program Files\Python39\;
C:\Windows\system32;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Windows\System32\OpenSSH\;
C:\Program Files\SASHome\SASFoundation\9.4\core\sasexe;
C:\Program Files\SASHome\SASFoundation\9.4\ets\sasexe;
C:\Program Files\SASHome\SASFoundation\9.4\dquality\sasexe;
C:\Program Files\SASHome\SASFoundation\9.4\dqualityssl\sasexe;
C:\Program Files\SASHome\SASFoundation\9.4\dmcommons\sasexe;
C:\Program Files\SASHome\Secure\ccme4;
C:\Program Files\SASHome\x86\Secure\ccme4;
C:\Program Files\MATLAB\R2021a\runtime\win64;
C:\Program Files\MATLAB\R2021a\bin;
C:\Program Files\Git\cmd;
C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;
C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;
C:\Users\ter58_RS\cmdstan\stan\lib\stan_math\lib\tbb;
C:\rtools42\mingw64\bin;
C:\Users\ter58_RS\AppData\Local\Microsoft\WindowsApps;
C:\rtools42\x86_64-w64-mingw32.static.posix\bin;
C:\rtools42\usr\bin;
C:\rtools42\ucrt64\bin;

It looks like there is definitely something strange going on. Your g++ version:

U:\>g++ --version
g++ (Built by Jeroen for the R-project) 8.3.0

Corresponds to the rtools40 toolchain, but your PATH entries are all for rtools42. That could be causing the issue of your compiler not being able to find the right libraries.

Another thing to check is where the compiler is looking for files, what output do you get from:

gcc --print-prog-name=cc1plus -v

and

echo | g++ -E -Wp,-v -xc++ -

Here’s the output. I’ll try to include rtools40 in PATH.

U:\>gcc --print-prog-name=cc1plus -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../libexec/gcc/x86_64-w64-mingw32.static.posix/10.4.0/lto-wrapper.exe
c:/rtools42/x86_64-w64-mingw32.static.posix/bin/../libexec/gcc/x86_64-w64-mingw32.static.posix/10.4.0/cc1plus.exe
U:\>echo | g++ -E -Wp,-v -xc++ -
ignoring nonexistent directory "c:\rtools42\x86_64-w64-mingw32.static.posix\bin\../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../../x86_64-w64-mingw32.static.posix/include"
ignoring duplicate directory "c:/rtools42/x86_64-w64-mingw32.static.posix/lib/gcc/../../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/include/c++"
ignoring duplicate directory "c:/rtools42/x86_64-w64-mingw32.static.posix/lib/gcc/../../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/include/c++/x86_64-w64-mingw32.static.posix"
ignoring duplicate directory "c:/rtools42/x86_64-w64-mingw32.static.posix/lib/gcc/../../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/include/c++/backward"
ignoring duplicate directory "c:/rtools42/x86_64-w64-mingw32.static.posix/lib/gcc/../../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/include"
ignoring nonexistent directory "/usr/lib/mxe/usr/x86_64-w64-mingw32.static.posix/include"
ignoring duplicate directory "c:/rtools42/x86_64-w64-mingw32.static.posix/lib/gcc/../../include"
ignoring duplicate directory "c:/rtools42/x86_64-w64-mingw32.static.posix/lib/gcc/../../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/include-fixed"
ignoring nonexistent directory "c:/rtools42/x86_64-w64-mingw32.static.posix/lib/gcc/../../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../../x86_64-w64-mingw32.static.posix/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 c:\rtools42\x86_64-w64-mingw32.static.posix\bin\../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/include/c++
 c:\rtools42\x86_64-w64-mingw32.static.posix\bin\../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/include/c++/x86_64-w64-mingw32.static.posix
 c:\rtools42\x86_64-w64-mingw32.static.posix\bin\../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/include/c++/backward
 c:\rtools42\x86_64-w64-mingw32.static.posix\bin\../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/include
 c:\rtools42\x86_64-w64-mingw32.static.posix\bin\../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/../../../../include
 c:\rtools42\x86_64-w64-mingw32.static.posix\bin\../lib/gcc/x86_64-w64-mingw32.static.posix/10.4.0/include-fixed
End of search list.
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "<stdin>"
ECHO is on.

I think the safer option would be to fully uninstall rtools40 and rtools42, and then reinstall rtools42 - just to be safe

This is a remote computer managed by my University, so not sure if that’s an option :(

Removing rtools42 and adding rtools40 to my PATH did not solve this

That does make things trickier. One more thing to check, what output do you get from:

where.exe g++
g++ -v

And also make sure to run

echo %PATH% 

To verify that the changes have registered

U:\>where.exe g++
C:\rtools40\mingw64\bin\g++.exe
C:\rtools42\x86_64-w64-mingw32.static.posix\bin\g++.exe
C:\rtools40\ucrt64\bin\g++.exe

U:\>g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=C:/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-8.3.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran --disable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Built by Jeroen for the R-project' --with-bugurl=https://github.com/r-windows --with-gnu-as --with-gnu-ld
Thread model: posix
gcc version 8.3.0 (Built by Jeroen for the R-project)