[R] Problems with installing R packages from source and running C++ in R, even on fresh R installation

Christophe Bousquet chr_bou@quet @end|ng |rom protonm@||@com
Thu Aug 31 16:01:54 CEST 2023


> So starting a new Rcmd.exe process fails for some reason.
> 
> If you take the same R session where the environment variables are
> right and Sys.which() resolves Make and GCC and try to run
> tools:::.shlib_internal(c('-n', 'hello.c')) or
> tools:::.shlib_internal('hello.c'), does it do something useful?

I think I tried the commands in the right R session. Here are all the output related to the environment variables for R as well as Sys.which():

```
> Sys.getenv("RTOOLS42_HOME")
[1] "C:/rtools42"
> Sys.getenv("RTOOLS43_HOME")
[1] "C:/rtools43"
> Sys.getenv("R_USER")
[1] "C:\\Users\\Christophe Bousquet\\Documents"
> Sys.getenv("R_RTOOLS43_PATH")
[1] "C:/rtools43/x86_64-w64-mingw32.static.posix/bin;C:/rtools43/usr/bin"
> Sys.getenv("R_LIBS_USER")
[1] "C:\\Users\\Christophe Bousquet\\AppData\\Local/R/win-library/4.3"
> Sys.getenv("R_LIBS_SITE")
[1] "C:/PROGRA~1/R/R-43~1.1/site-library"
> Sys.getenv("R_HOME")
[1] "C:/PROGRA~1/R/R-43~1.1"
> Sys.getenv("R_COMPILED_BY")
[1] "gcc 12.2.0"
> Sys.getenv("R_ARCH")
[1] "/x64"
> Sys.which("Make")
                              Make 
"C:\\rtools43\\usr\\bin\\Make.exe" 
> Sys.which("GCC")
                                       GCC 
"C:\\rtools43\\X86_64~1.POS\\bin\\GCC.exe"
```

So when I run the commands, I get this output. I honestly have no clue whether this can be considered as something useful or not :-/

```
> tools:::.shlib_internal(c('-n', 'hello.c'))
make cmd is
  make -f "C:/PROGRA~1/R/R-43~1.1/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-43~1.1/share/make/winshlib.mk" SHLIB="hello.dll" WIN=64 TCLBIN= OBJECTS="hello.o"

make would use
gcc  -I"C:/PROGRA~1/R/R-43~1.1/include" -DNDEBUG     -I"C:/rtools43/x86_64-w64-mingw32.static.posix/include"     -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -c hello.c -o hello.o
if test "zhello.o" != "z"; then \
  if test -e "hello-win.def"; then \
    echo gcc  -shared -s -static-libgcc -o hello.dll hello-win.def hello.o  -L"C:/rtools43/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools43/x86_64-w64-mingw32.static.posix/lib"  -L"C:/PROGRA~1/R/R-43~1.1/bin/x64" -lR ; \
    gcc  -shared -s -static-libgcc -o hello.dll hello-win.def hello.o  -L"C:/rtools43/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools43/x86_64-w64-mingw32.static.posix/lib"  -L"C:/PROGRA~1/R/R-43~1.1/bin/x64" -lR ; \
  else \
    echo EXPORTS > tmp.def; \
    nm hello.o | sed -n 's/^.* [BCDRT] / /p' | sed -e '/[.]refptr[.]/d' -e '/[.]weak[.]/d' | sed 's/[^ ][^ ]*/"&"/g'  >> tmp.def; \
    echo gcc  -shared -s -static-libgcc -o hello.dll tmp.def hello.o  -L"C:/rtools43/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools43/x86_64-w64-mingw32.static.posix/lib"  -L"C:/PROGRA~1/R/R-43~1.1/bin/x64" -lR ; \
    gcc  -shared -s -static-libgcc -o hello.dll tmp.def hello.o  -L"C:/rtools43/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools43/x86_64-w64-mingw32.static.posix/lib"  -L"C:/PROGRA~1/R/R-43~1.1/bin/x64" -lR ; \
    rm -f tmp.def; \
  fi \
fi
[1] 0



> tools:::.shlib_internal('hello.c')
using C compiler: ‘gcc.exe (GCC) 12.2.0’
gcc  -I"C:/PROGRA~1/R/R-43~1.1/include" -DNDEBUG     -I"C:/rtools43/x86_64-w64-mingw32.static.posix/include"     -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -c hello.c -o hello.o
gcc -shared -s -static-libgcc -o hello.dll tmp.def hello.o -LC:/rtools43/x86_64-w64-mingw32.static.posix/lib/x64 -LC:/rtools43/x86_64-w64-mingw32.static.posix/lib -LC:/PROGRA~1/R/R-43~1.1/bin/x64 -lR
[1] 0
```



> (I'm still debugging from first principles. Duncan Murdoch is likely
> right that adding the environment variables, either
> RTOOLS43_HOME=c:/rtools43 or adjusting PATH as described above, could
> help.)

I think that my environment variables and paths are correct. But I did not fully understand how to adjust PATH. I already tried a few things along these lines, but it never solved my problem. And I somehow assumed that by uninstalling/reinstalling all R-related things, the paths and variables would also be reset.



More information about the R-help mailing list