stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.04k stars 268 forks source link

Compalitation errors when running stanc and stan_model on Windows #926

Open wolski opened 3 years ago

wolski commented 3 years ago

Summary:

Can't build stan model using stanc and stan_model

Reproducible Steps:

library(rstan)
fixed_effect <- 
"data {
  int<lower=1> N; //number of data points
  int<lower=1> K;
  real intensity[N]; //protein or peptide intensity
  matrix[N,K] dilution;  //design matrix (predictor)
}

parameters {
  vector[K] beta;            //intercept and slope
  real<lower=0> sigma_e;     //error sd
}

model {
  intensity ~ normal(dilution * beta , sigma_e);
}
"

rt <- stanc(model_code = fixed_effect)
sm <- stan_model(stanc_ret = rt, verbose = FALSE)

Current Output:

> sm <- stan_model(stanc_ret = rt, verbose = FALSE)
make cmd is
  make -f "C:/PROGRA~1/R/R-40~1.3/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-40~1.3/share/make/winshlib.mk" CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB="file9746d052a95.dll" WIN=64 TCLBIN=64 OBJECTS="file9746d052a95.o"

make would use
if test "zfile9746d052a95.o" != "z"; then \
  if test -e "file9746d052a95-win.def"; then \
    echo "C:/rtools40/mingw64/bin/"g++  -shared -s -static-libgcc -o file9746d052a95.dll file9746d052a95-win.def file9746d052a95.o   "C:/Users/wewol/OneDrive/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a" -L"C:/Users/wewol/OneDrive/Documents/R/win-library/4.0/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/wewol/OneDrive/Documents/R/win-library/4.0/RcppParallel/lib/x64" -ltbb  -L"C:/PROGRA~1/R/R-40~1.3/bin/x64" -lR ; \
    "C:/rtools40/mingw64/bin/"g++  -shared -s -static-libgcc -o file9746d052a95.dll file9746d052a95-win.def file9746d052a95.o   "C:/Users/wewol/OneDrive/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a" -L"C:/Users/wewol/OneDrive/Documents/R/win-library/4.0/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/wewol/OneDrive/Documents/R/win-library/4.0/RcppParallel/lib/x64" -ltbb  -L"C:/PROGRA~1/R/R-40~1.3/bin/x64" -lR ; \
  else \
    echo EXPORTS > tmp.def; \
    "C:/rtools40/mingw64/bin/"nm file9746d052a95.o | sed -n 's/^.* [BCDRT] / /p' | sed -e '/[.]refptr[.]/d' -e '/[.]weak[.]/d' | sed 's/[^ ][^ ]*/"&"/g'  >> tmp.def; \
    echo "C:/rtools40/mingw64/bin/"g++  -shared -s -static-libgcc -o file9746d052a95.dll tmp.def file9746d052a95.o   "C:/Users/wewol/OneDrive/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a" -L"C:/Users/wewol/OneDrive/Documents/R/win-library/4.0/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/wewol/OneDrive/Documents/R/win-library/4.0/RcppParallel/lib/x64" -ltbb  -L"C:/PROGRA~1/R/R-40~1.3/bin/x64" -lR ; \
    "C:/rtools40/mingw64/bin/"g++  -shared -s -static-libgcc -o file9746d052a95.dll tmp.def file9746d052a95.o   "C:/Users/wewol/OneDrive/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a" -L"C:/Users/wewol/OneDrive/Documents/R/win-library/4.0/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/wewol/OneDrive/Documents/R/win-library/4.0/RcppParallel/lib/x64" -ltbb  -L"C:/PROGRA~1/R/R-40~1.3/bin/x64" -lR ; \
    rm -f tmp.def; \
  fi \
fi
Error in compileCode(f, code, language = language, verbose = verbose) : 
  C:/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/wewol/OneDrive/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a(stan_fit.o):stan_fit.cpp:(.data$_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2P1[_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2P1]+0x0): multiple definition of `boost::math::detail::bessel_j0<long double>(long double)::P1'; file9746d052a95.o:file9746d052a95.cpp:(.rdata$_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2P1[_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2P1]+0x0): first defined hereC:/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/wewol/OneDrive/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a(stan_fit.o):stan_fit.cpp:(.data$_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2QS[_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2QS]+0x0): multiple definition of `boost::math::detail::bessel_j0<long double>(long double)::QS'; file9746d052a95.o
Error in sink(type = "output") : invalid connection

RStan Version:

packageVersion("rstan")
[1] ‘2.21.2’

R Version:

The version of R you are running (e.g., from R.version.string)

> R.version.string
[1] "R version 4.0.3 (2020-10-10)"

Operating System:

Windows 10.

andrjohns commented 3 years ago

Sorry for taking so long to get to this. This error is caused by a recent update to the BH package, to fix you just need to reinstall rstan and StanHeaders from source:

# Compile packages using all cores
Sys.setenv(MAKEFLAGS = paste0("-j",parallel::detectCores()))

install.packages(c("StanHeaders","rstan"),type="source")