Christophe Bousquet
2023-Aug-31 14:01 UTC
[R] Problems with installing R packages from source and running C++ in R, even on fresh R installation
> 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.
Ivan Krylov
2023-Aug-31 14:21 UTC
[R] Problems with installing R packages from source and running C++ in R, even on fresh R installation
? Thu, 31 Aug 2023 14:01:54 +0000 Christophe Bousquet <chr_bousquet at protonmail.com> ?????:> 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"This can be considered good news. You have just successfully performed the job that is normally done by R CMD SHLIB when installing source packages or running inline C++ code. The environment variables, at least inside your running R session, are completely fine. Now we need to find out why R CMD SHLIB itself fails without producing any output. Do you get any output from tools::Rcmd('SHLIB --version')? Does tools::Rcmd('') print the list of available options?> But I did not fully understand how to adjust PATH.This WikiHow article points in the right direction: https://www.wikihow.com/Change-the-PATH-Environment-Variable-on-Windows It might help to prepend C:\\rtools43/x86_64-w64-mingw32.static.posix/bin;C:\\rtools43/usr/bin; ...to the existing value of PATH. On the other hand, it might not. I don't yet have a good explanation why your Rcmd.exe seemingly refuses to work. -- Best regards, Ivan
Possibly Parallel Threads
- Problems with installing R packages from source and running C++ in R, even on fresh R installation
- Problems with installing R packages from source and running C++ in R, even on fresh R installation
- Problems with installing R packages from source and running C++ in R, even on fresh R installation
- Problems with installing R packages from source and running C++ in R, even on fresh R installation
- Problems with installing R packages from source and running C++ in R, even on fresh R installation