Compiling on WIndows with MSVC / Visual C++

A while ago I tried compiling a simple C++ program that uses the multi_normal_lpdf function in the Stan Math library. I got some compiler errors from the Intel compiler and from the MSVC compiler. I managed to fix the Intel error, but not the MSVC one.

One of replies was,

I am coming back to this now because I would like to use another C++ library that is only compatible with MSVC.

So it would be nice to know whether you have made any progress in resolving the MSVC issues. I would be interested to know more the details of why this is an issue. The error messages that the compiler is giving me are not particularly enlightening.

Here is some source code that I am using as a test case,

#include <stan/math.hpp>
#include <iostream>

int main() {
  Eigen::Matrix<double, Eigen::Dynamic, 1> y(3, 1);
  y << 2.0, -2.0, 11.0;
  Eigen::Matrix<double, Eigen::Dynamic, 1> mu(3, 1);
  mu << 1.0, -1.0, 3.0;
  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> Sigma(3, 3);
  Sigma << 9.0, -3.0, 0.0, -3.0, 4.0, 0.0, 0.0, 0.0, 5.0;

  std::cout << stan::math::multi_normal_lpdf(y, mu, Sigma);

  return 0;

And here is the error message I get,

.../stan-dev/math/stan/math/rev/mat/functor/adj_jac_apply.hpp(410): fatal error C1001: An internal error has occurred in the compiler.
(compiler file 'msc1.cpp', line 1518)
 To work around this problem, try simplifying or changing the program near the locations listed above.
Please choose the Technical Support command on the Visual C++
 Help menu, or open the Technical Support help file for more information
Internal Compiler Error in C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\cl.exe.  You will be prompted to send an error report to Microsoft later.
1 Like

My guess is that msvc has a bug in template parsing.

clang-cl works fine if you can use it as a drop-in placement for cl.exe

Yeah, MSVC has template bugs that prevent the compilation of code in the Eigen C++ library which is a critical dependency for the Stan math library.

@philipm Being able to support MSVC would be great. In the short term, understanding precisely what the Eigen incompatibility is would be valuable. I searched for this at one point and didn’t find anything terribly definitive.

In addition to understanding the incompatibility (and if there’s anything that can be done Stan-side), it would be really valuable to identify if there is any prospect for the incompatibility being resolved with a future version of Eigen or MSVC. My sense is that some incompatibilities with MSVC and Eigen have been resolved in the past.