@@ -740,25 +740,30 @@ with_cmdstan_flags <- function(expr) {
740
740
741
741
libs <- c(" LDLIBS" , " LIBSUNDIALS" , " TBB_TARGETS" , " LDFLAGS_TBB" )
742
742
libs <- paste(sapply(libs , get_cmdstan_flags ), collapse = " " )
743
- if (.Platform $ OS.type == " windows " ) {
743
+ if (os_is_windows() ) {
744
744
libs <- paste(libs , " -fopenmp -lstdc++" )
745
745
}
746
746
lib_paths <- c(" /stan/lib/stan_math/lib/tbb/" ,
747
747
" /stan/lib/stan_math/lib/sundials_6.1.1/lib/" )
748
+ new_makevars <- c(
749
+ PKG_CPPFLAGS = ifelse(cmdstan_version() < = " 2.30.1" , " -DCMDSTAN_JSON" , " " ),
750
+ PKG_CXXFLAGS = paste(cxxflags , cmdstanr_includes , r_includes , collapse = " " ),
751
+ PKG_LIBS = libs
752
+ )
753
+ if (os_is_windows()) {
754
+ new_makevars <- c(
755
+ new_makevars ,
756
+ SHLIB_LD = paste0(rtools4x_toolchain_path()," /gcc" ),
757
+ LOCAL_CPPFLAGS = paste0(" -L'" ,rtools4x_toolchain_path()," /../include'" ),
758
+ LOCAL_LIBS = paste0(" -L'" ,rtools4x_toolchain_path()," /../lib'" )
759
+ )
760
+ }
748
761
withr :: with_path(
749
762
c(
750
763
paste0(cmdstan_path(), lib_paths ),
751
764
toolchain_PATH_env_var()
752
765
),
753
- withr :: with_makevars(
754
- c(
755
- USE_CXX14 = 1 ,
756
- PKG_CPPFLAGS = ifelse(cmdstan_version() < = " 2.30.1" , " -DCMDSTAN_JSON" , " " ),
757
- PKG_CXXFLAGS = paste(cxxflags , cmdstanr_includes , r_includes , collapse = " " ),
758
- PKG_LIBS = libs
759
- ),
760
- expr
761
- )
766
+ withr :: with_makevars(new_makevars , expr )
762
767
)
763
768
}
764
769
@@ -818,11 +823,16 @@ expose_model_methods <- function(env, force_recompile = FALSE, verbose = FALSE)
818
823
}
819
824
820
825
methods_dll <- tempfile(fileext = .Platform $ dynlib.ext )
826
+ envvar <- c(" current" )
827
+ if (os_is_windows()) {
828
+ envvar <- c(envvar , " BINPREF" = paste0(rtools4x_toolchain_path(), " /" ))
829
+ }
821
830
with_cmdstan_flags(
822
831
processx :: run(
823
832
command = file.path(R.home(component = " bin" ), " R" ),
824
833
args = c(" CMD" , " SHLIB" , repair_path(model_obj_file ), repair_path(precomp_methods_file ),
825
834
" -o" , repair_path(methods_dll )),
835
+ env = envvar ,
826
836
echo = verbose || is_verbose_mode(),
827
837
echo_cmd = is_verbose_mode(),
828
838
error_on_status = FALSE
0 commit comments