Using GCC in rtools42 to compile C files struggle

28 views Asked by At

I'm extremely stumped.

Long story short, I can no longer use a commonly used code by our group to make simulations using rtools to compile in C (to make computation time much faster). It worked forever, but now that I am using a newer laptop with the newest Rtools (rtools42), I absolutely cannot get it to work at all. I am not totally confident about the inner workings of the old code, which makes it difficult for me to know how to update it properly.

A lot about the rtools directory has changed since we used this code. The original code, which was used with Rtools ver. 3.4.0.1964:

rtools <- "C:\\Rtools\\bin"
gcc <- "C:\\Rtools\\gcc-4.6.3\\bin"
path <- strsplit(Sys.getenv("PATH"), ";")[[1]]
new_path <- c(rtools, gcc, path)
new_path <- new_path[!duplicated(tolower(new_path))]
Sys.setenv(PATH = paste(new_path, collapse = ";"))

# Working directory (put .c file and parameters file here)
setwd("C:/Users/test")

# compile my model from C definition
dyn.unload("C:/Users/test/Model.dll") # unload dll
system("C:/Users/test/R CMD SHLIB Model.c")
dyn.load("C:/Users/test/Model.dll") # Load dll

I have made it far enough to realize that the rtools and gcc object lines are likely the source of all the problems, since rtools42 has significantly different directory paths than Rtools did. I have tried to change these lines of code. I think the rtools object is right now, but I don't think I'm correctly loading the GCC. I searched in my rtools42 folder for gcc.exe, and I have 2 files, but neither path works...

Any insight? Thanks.

rtools <- "C:\\rtools42\\usr\\bin"
gcc <- "C:\\rtools42\\x86_64-w64-mingw32.static.posix\\bin"
path <- strsplit(Sys.getenv("PATH"), ";")[[1]]
new_path <- c(rtools, gcc, path)
new_path <- new_path[!duplicated(tolower(new_path))]
Sys.setenv(PATH = paste(new_path, collapse = ";"))

# compile my model from C definition
dyn.unload("C:/Users/test/Model.dll") # unload dll
system("C:/Users/test/R CMD SHLIB Model.c")
dyn.load("C:/Users/test/Model.dll") # Load dll

where I get this error when I try to load the .dll:

Error in inDL(x, as.logical(local), as.logical(now), ...) : 
  unable to load shared object 'C:/Users/test/Model.dll':
  LoadLibrary failure:  The specified module could not be found.
0

There are 0 answers