I have created an rcpp packages which uses rcppeigen. Installing and using it on linux nad macos works just fine but when i try to install it on windows it gets stuck on: ** testing if installed package can be loaded from temporary location
With no error messages or anything
(devtools::install_github("Avriox/BISAM", verbose = TRUE, force = TRUE)
Downloading GitHub repo Avriox/BISAM@HEAD
── R CMD build ──────────────────────────────────────────────────────────────────────────────────────
✔ checking for file 'C:\Users\lkonrad\AppData\Local\Temp\RtmpQ7LKkr\remotes2ae85217126\Avriox-BISAM-516adb1/DESCRIPTION' (656ms)
─ preparing 'BISAM': (392ms)
✔ checking DESCRIPTION meta-information ...
─ cleaning src
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
Omitted 'LazyData' from DESCRIPTION
─ building 'BISAM_0.0.1.tar.gz'
Installing package into ‘C:/SpecProF/R-Libs’
(as ‘lib’ is unspecified)
system (cmd0): C:/PROGRA1/R/R-441.1/bin/x64/R CMD INSTALL
installing source package 'BISAM' ...
** using staged installation
** libs
using C++ compiler: 'G__1.EXE (GCC) 13.2.0'
using C++17
g++ -std=gnu++17 -I"C:/PROGRA1/R/R-441.1/include" -DNDEBUG -I'C:/SpecProF/R-Libs/Rcpp/include' -I'C:/SpecProF/R-Libs/RcppEigen/include' -I"C:/SpecProF/Rtools/x86_64-w64-mingw32.static.posix/include" -fopenmp -w -O3 -march=native -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c RcppExports.cpp -o RcppExports.o
g++ -std=gnu++17 -I"C:/PROGRA1/R/R-441.1/include" -DNDEBUG -I'C:/SpecProF/R-Libs/Rcpp/include' -I'C:/SpecProF/R-Libs/RcppEigen/include' -I"C:/SpecProF/Rtools/x86_64-w64-mingw32.static.posix/include" -fopenmp -w -O3 -march=native -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c b_ism.cpp -o b_ism.o
g++ -std=gnu++17 -I"C:/PROGRA1/R/R-441.1/include" -DNDEBUG -I'C:/SpecProF/R-Libs/Rcpp/include' -I'C:/SpecProF/R-Libs/RcppEigen/include' -I"C:/SpecProF/Rtools/x86_64-w64-mingw32.static.posix/include" -fopenmp -w -O3 -march=native -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c main.cpp -o main.o
g++ -std=gnu++17 -I"C:/PROGRA1/R/R-441.1/include" -DNDEBUG -I'C:/SpecProF/R-Libs/Rcpp/include' -I'C:/SpecProF/R-Libs/RcppEigen/include' -I"C:/SpecProF/Rtools/x86_64-w64-mingw32.static.posix/include" -fopenmp -w -O3 -march=native -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c model_selection/ms_base.cpp -o model_selection/ms_base.o
g++ -std=gnu++17 -I"C:/PROGRA1/R/R-441.1/include" -DNDEBUG -I'C:/SpecProF/R-Libs/Rcpp/include' -I'C:/SpecProF/R-Libs/RcppEigen/include' -I"C:/SpecProF/Rtools/x86_64-w64-mingw32.static.posix/include" -fopenmp -w -O3 -march=native -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c model_selection/ms_no_optimization.cpp -o model_selection/ms_no_optimization.o
g++ -std=gnu++17 -I"C:/PROGRA1/R/R-441.1/include" -DNDEBUG -I'C:/SpecProF/R-Libs/Rcpp/include' -I'C:/SpecProF/R-Libs/RcppEigen/include' -I"C:/SpecProF/Rtools/x86_64-w64-mingw32.static.posix/include" -fopenmp -w -O3 -march=native -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c model_selection/ms_parallel_z.cpp -o model_selection/ms_parallel_z.o
g++ -std=gnu++17 -I"C:/PROGRA1/R/R-441/R/R-441/R/R-441/R/R-441/R/R-441/R/R-441/R/R-441/R/R-441/R/R-441/R/R-441/R/R-441/R/R-44~1.1/bin/x64 -lR
installing to C:/SpecProF/R-Libs/00LOCK-BISAM/00new/BISAM/libs/x64
** R
** byte-compile and prepare package for lazy loading
** help
No man pages found in package 'BISAM'
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location)
Include all .cpp files in src/ and its subdirectories
SOURCES = $(wildcard *.cpp /.cpp)
Generate object file names
OBJECTS = $(SOURCES:.cpp=.o)
Rule to build the shared library
(SHLIB):(OBJECTS)
Why does it get stuck and how can i fix it
The issue you're experiencing is likely due to platform-specific differences in how your C++ code interacts with Windows during the package loading process. Specifically, the problem may be in your Makevars.win file and how it's configured for the Windows environment.
Here's what you can do to resolve the issue:
Simplify Your Makevars.win File:
Your current Makevars.win may be introducing conflicts or unnecessary complexities that interfere with the standard build process on Windows. Here's a simplified version you can try:
Remove Custom Compiler and Linker Flags: By removing explicit definitions of CC, CXX, SOURCES, OBJECTS, and custom $(SHLIB) rules, you let R's build system use its default settings, which are more likely to work across different environments.
Adjust Optimization Level: Using -O2 instead of -O3 (and removing -march=native) can prevent issues related to aggressive optimization and architecture-specific instructions that may not be compatible across different Windows systems.
Handle OpenMP Flags Properly: Ensure that OpenMP flags are included correctly with $(SHLIB_OPENMP_CXXFLAGS).
Test the Installation:
After simplifying Makevars.win, try reinstalling your package:
devtools::install_github("Avriox/BISAM", verbose = TRUE, force = TRUE)
If the package installs successfully, the issue was likely due to the complexities in the original Makevars.win file.
Check for OpenMP Issues:
Windows has known challenges with OpenMP support. To test if OpenMP is the culprit:
Disable OpenMP: Temporarily remove OpenMP flags to see if the package installs without them.
Update your Makevars.win:
CXX_STD = CXX17
PKG_CXXFLAGS = -w -O2
PKG_LIBS =
Reinstall the Package: Try reinstalling your package without OpenMP to see if the installation completes.
If OpenMP Is the Issue: You'll need to adjust your code to handle OpenMP differently on Windows or conditionally compile OpenMP code only on platforms where it's fully supported.
Investigate Your C++ Code:
If simplifying Makevars.win and adjusting OpenMP settings don't resolve the issue, the problem may lie within your C++ code. Specifically:
Static Initializations or Global Objects: Check for any static variables or objects that are initialized when the DLL is loaded. These can sometimes cause hangs if they perform complex operations or have platform-specific issues.
Platform-Specific Code: Ensure that any code that might behave differently on Windows is correctly handled. Pay attention to file paths, threading, synchronization primitives, and other OS-related functionalities.
Infinite Loops or Deadlocks: Look for any loops or threading mechanisms that might hang on Windows due to differences in how threading is implemented.
Add Diagnostic Messages:
Use Rcpp's Diagnostic Tools: Insert Rcpp::Rcout statements in your C++ code to print diagnostic messages.
Check .onLoad Functions: If you have any .onLoad, .onAttach, or similar functions in your R code, add print statements to ensure they aren't causing the hang.
Compile with Debugging Symbols:
Add Debugging Flags: Modify your Makevars.win to include debugging symbols:
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) -w -O0 -g
Use a Debugger: Run R under a debugger like gdb or use Windows debugging tools to see where it's hanging during the package loading process.
Check for BLAS/LAPACK Linking Issues:
Remove Explicit Linking: Since R handles BLAS and LAPACK linking, you generally don't need to link against them explicitly. Remove the following from your Makevars.win:
Test Installation Again: Incorrect linkage to BLAS/LAPACK can cause hangs or crashes during loading.
Consult Logs and Verbose Outputs:
Increase Verbosity: Run the installation with maximum verbosity to capture any hidden error messages.
Check Windows Event Viewer: Sometimes, crashes or hangs will leave logs in the Windows Event Viewer under Application Logs.
Environment Differences:
Ensure Consistent Toolchains: Verify that your Rtools installation and toolchains are correctly set up and that there are no conflicts between 32-bit and 64-bit environments.
Check for Missing Dependencies: Make sure all dependencies, including Rcpp and RcppEigen, are up to date and compatible with your version of R on Windows.
By simplifying your Makevars.win file and carefully reviewing your code for Windows-specific issues, you should be able to resolve the installation hang. If the problem persists after these steps, consider sharing a minimal reproducible example of your code for further investigation.