Unable to install fortran based packages in R - "gfortran -m32:not found" - r

I am writing an R package that has Fortran source code. In short, my problem is when I try to install the package I get the error "gfortran -m32: not found" however, I am able compile my code using gfortran -m32 when I'm not installing the package.
Detailed Version:
I have installed the newest version of R(3.1.1) along with the newest version of Rtools(31) and renamed my path variables accordingly (C:\Rtools\bin;C:\Rtools\gcc-4.6.3\bin;C:\Program Files\R\R-3.1.1\bin\x64;C:\msys;C:\Program Files (x86)\SSH Secure Shell;C:\Program Files\MiKTeX 2.9\miktex\bin).
For testing purposes, I downloaded the PropClust package from CRAN which has Fortran source code.
When I type "R CMD INSTALL PropClust_1.4.tar.gz" after building it, I get the following error:
* installing *source* package 'PropClust' ...
** libs
*** arch - i386
C:/PROGRA~1/R/R-31~1.1/etc/i386/Makeconf:202: warning: overriding recipe for target `.m.o'
C:/PROGRA~1/R/R-31~1.1/etc/i386/Makeconf:195: warning: ignoring old recipe for target `.m.o'
gfortran -m32 -O3 -mtune=core2 -c PropClustParallelTrials.f90 -o PropClustParallelTrials.o
gcc -m32 -I"C:/PROGRA~1/R/R-31~1.1/include" -DNDEBUG -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O3 -Wall -std=gnu99 -mtune=core2 -c minWhichMin.c -o minWhichMin.o
gfortran -m32 -shared -s -static-libgcc -o PropClust.dll tmp.def PropClustParallelTrials.o minWhichMin.o -Ld:/RCompile/CRANpkg/extralibs64/local/lib/i386 -Ld:/RCompile/CRANpkg/extralibs64/local/lib -LC:/PROGRA~1/R/R-31~1.1/bin/i386 -lR
gfortran -m32: not found
C:/PROGRA~1/R/R-31~1.1/etc/i386/Makeconf:202: warning: overriding recipe for target `.m.o'
C:/PROGRA~1/R/R-31~1.1/etc/i386/Makeconf:195: warning: ignoring old recipe for target `.m.o'
cygwin warning:
MS-DOS style path detected: C:/PROGRA~1/R/R-31~1.1/bin/i386/Rterm.exe
Preferred POSIX equivalent is: /cygdrive/c/PROGRA~1/R/R-31~1.1/bin/i386/Rterm.exe
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
no DLL was created
ERROR: compilation failed for package 'PropClust'
* removing 'C:/Users/kamicz/Documents/IsotopeR/PropClust.Rcheck/PropClust'
Although it says "gfortran -m32: not found" I have compiled my code in the same window with the same options(gfortran -m32 -O3 -mtne=core2 -c a.f90 -o a.out) with no problems. Has anyone had this problem before? I am running Windows 7 64-bit if that matters.

I had a similar problem : R was invoking gfortran-4.8 - an unrecognized command on my system - instead of gfortran. This problem was fixed upon creating the file ~/.R/Makevars within my home directory. Here are the contents of Makevars which points to the appropriate gfortran installation:
F77 = gfortran
FC = gfortran
FLIBS = -L/usr/local/gfortran/lib

Related

Issues installing RcppMP in MacOS

I am trying to install RcppMP in MacOS.
However, when I type:
remotes::install_github("Thell/RcppMP",dependencies = T)
I get the following error:
* installing *source* package ‘RcppMP’ ...
** using staged installation
** libs
clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I../inst/include/ -I'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/BH/include' -I'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include' -I/usr/local/include -fPIC -Wall -g -O2 -c RcppExports.cpp -o RcppExports.o
In file included from RcppExports.cpp:4:
In file included from ./../inst/include/RcppMP.h:7:
In file included from ../inst/include/RcppMP_RcppExports.h:7:
../inst/include/RcppMP_types.hpp:15:10: fatal error: 'mpreal.h' file not found
#include <mpreal.h>
^~~~~~~~~~
1 error generated.
make: *** [RcppExports.o] Error 1
ERROR: compilation failed for package ‘RcppMP’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppMP’
Warning message:
In i.p(...) :
installation of package ‘/var/folders/pq/hxwd9my563q_qpy4rbrlgkmw0000gn/T//RtmpIdnyiB/file2184610d74ea/RcppMP_0.1.1.tar.gz’ had non-zero exit status
My ~/.R/Makevars file contain the following specifications:
CC=/usr/local/opt/llvm/bin/clang
CXX=/usr/local/opt/llvm/bin/clang++
CXX1X=/usr/local/opt/llvm/bin/clang++
LDFLAGS=-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib
CXXFLAGS=-I/usr/local/opt/llvm/include
FLIBS=-L/usr/local/Cellar/gcc/11.3.0_1/lib/gcc/11
This was a bit more complicated than I thought; this package requires mpfr, gmp and the very-similarly-named mpfrc++. The steps that worked for me are:
Install gmp and mpfr via homebrew
Download and unzip "mpfrc++-3.6.8.zip" from
http://www.holoborodko.com/pavel/mpfr/#download
Copy the mpreal header file ("mpreal.h") to
/usr/local/include (sudo cp ./mpreal.h /usr/local/include/) or, in your case, perhaps sudo cp ./mpreal.h /usr/local/opt/llvm/include would make more sense
Install/compile RcppMP
(remotes::install_github("Thell/RcppMP",dependencies = TRUE))
I got some warnings but no errors, and the package loaded (library(RcppMP)), so I'm relatively confident it installed successfully. If you find otherwise, please let me know and I'll look into it further.

Linux issue happens on Windows? "fatal error: fftw3.h: No such file or directory"

I am running MRO 3.5.0 on Win10, and trying to install a package image.CannyImage from bnosac/image on the github. But it keeps reporting fatal errors as following.
* installing *source* package 'image.CannyEdges' ...
** libs
c:/Rtools/mingw_64/bin/g++ -m64 -I"C:/PROGRA~1/MICROS~1/ROPEN~1/R-35~1.0/include" -DNDEBUG -I"C:/Users/eric1/Documents/R/win-library/3.5/Rcpp/include" -I"C:/swarm/workspace/External-R-3.5.0/vendor/extsoft/include" -O2 -Wall -mtune=core2 -c RcppExports.cpp -o RcppExports.o
c:/Rtools/mingw_64/bin/gcc -m64 -I"C:/PROGRA~1/MICROS~1/ROPEN~1/R-35~1.0/include" -DNDEBUG -I"C:/Users/eric1/Documents/R/win-library/3.5/Rcpp/include" -I"C:/swarm/workspace/External-R-3.5.0/vendor/extsoft/include" -O2 -Wall -std=gnu99 -mtune=core2 -c adsf.c -o adsf.o
c:/Rtools/mingw_64/bin/g++ -m64 -I"C:/PROGRA~1/MICROS~1/ROPEN~1/R-35~1.0/include" -DNDEBUG -I"C:/Users/eric1/Documents/R/win-library/3.5/Rcpp/include" -I"C:/swarm/workspace/External-R-3.5.0/vendor/extsoft/include" -O2 -Wall -mtune=core2 -c rcpp_canny.cpp -o rcpp_canny.o
In file included from rcpp_canny.cpp:13:0:
canny.h:8:19: fatal error: fftw3.h: No such file or directory
#include <fftw3.h>
^
compilation terminated.
make: *** [C:/PROGRA~1/MICROS~1/ROPEN~1/R-35~1.0/etc/x64/Makeconf:215: rcpp_canny.o] Error 1
ERROR: compilation failed for package 'image.CannyEdges'
* removing 'C:/Users/eric1/Documents/R/win-library/3.5/image.CannyEdges'
In R CMD INSTALL
Installation failed: Command failed (1)
^
compilation terminated.
Google says I can solve the issue by sudo apt-get remove libfftw3-dev. Unfortunately, I am on Windows, and some advised, apply lib /machine:i386 /def:libfftw3-3.def on cmd mode. Ouch, there is no such command or file called lib.exe on Win10.
Please advise, how I can solve this issue on my Win10+MRO system. Thanks.
Even though this question is already a bit old:
By now (Feb 2020) there are precompiled packages available that work also under Windows:
Canny Edges - Package
and more general:
List of all available packages
I have tried installing them and (at least for me) it worked.

R compilation failed for package fst

I'm trying to install fst R package from CRAN but I get error:
gcc -I"/path/apps/R/3.5.1-20180807-test/x86_64-linux-2.6-rhel6/lib64/R/include" -DNDEBUG
-fopenmp -I. -Ifstcore -Ifstcore_v1 -Ifstcore/LZ4 -Ifstcore/ZSTD -Ifstcore/ZSTD/common
-Ifstcore/ZSTD/decompress -Ifstcore/ZSTD/compress
-I"/path/apps/R/3.5.1-20180807-test/x86_64-linux-2.6-rhel6/r_libs_site/Rcpp/include"
-I /path/apps/R/static-zlib-gcc6.3/x86_64-linux-2.6-rhel6/include -fpic
-I /path/apps/R/static-zlib-gcc6.3/x86_64-linux-2.6-rhel6/include
-c fstcore/ZSTD/compress/huf_compress.c -o fstcore/ZSTD/compress/huf_compress.o
gcc -I"/path/apps/R/3.5.1-20180807-test/x86_64-linux-2.6-rhel6/lib64/R/include" -DNDEBUG
-fopenmp -I. -Ifstcore -Ifstcore_v1 -Ifstcore/LZ4 -Ifstcore/ZSTD -Ifstcore/ZSTD/common
-Ifstcore/ZSTD/decompress -Ifstcore/ZSTD/compress
-I"/path/apps/R/3.5.1-20180807-test/x86_64-linux-2.6-rhel6/r_libs_site/Rcpp/include"
-I /path/apps/R/static-zlib-gcc6.3/x86_64-linux-2.6-rhel6/include -fpic
-I /path/apps/R/static-zlib-gcc6.3/x86_64-linux-2.6-rhel6/include
-c fstcore/ZSTD/decompress/zstd_decompress.c -o fstcore/ZSTD/decompress/zstd_decompress.o
/tmp/cc0LoSFX.s: Assembler messages:
/tmp/cc0LoSFX.s:7353: Error: no such instruction: `shlx %rax,%rdx,%rax'
/tmp/cc0LoSFX.s:8204: Error: no such instruction: `shlx %rax,%rdx,%rax'
/tmp/cc0LoSFX.s:8608: Error: no such instruction: `shlx %rax,%rdx,%rax'
make: *** [fstcore/ZSTD/decompress/zstd_decompress.o] Error 1
ERROR: compilation failed for package ‘fst’
I there any required linux library that can be compiled from source? What else I can do?
EDIT:
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/path/apps/gcc/6.3.0/x86_64-linux-2.6-rhel6/bin/../libexec/gcc/x86_64-pc-linux-gnu/6.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/path/apps/gcc/6.3.0/x86_64-linux-2.6-rhel6 --disable-multilib
Thread model: posix
gcc version 6.3.0 (GCC)
Putting this here for posterity in case others eventually land on this question when facing similar issues.
It turns out that as far as we can tell, the problem was incompatible versions of the assembler (/usr/bin/as) and gcc (our non-system 6.3.0 installation).
So if you landed here at the end of your rope with no idea why you're seeing these errors, looking into getting a compatible version of the assembler (in linux world this is part of the binutils module/project). Hope that helps.

loop_apply.o: file not recognized: File format not recognized

I am trying to install R’s plyr package. Here is the error message:
* installing *source* package ‘plyr’ ...
** package ‘plyr’ successfully unpacked and MD5 sums checked
** libs
clang++ -I/opt/R-3.4.1/include -DNDEBUG -I"/home/isomorphismes/R/i686-pc-linux-gnu-library/3.4/Rcpp/include" -I/usr/local/include -fpic -I/opt/boost_1_61_0/boost -c RcppExports.cpp -o RcppExports.o
clang -I/opt/R-3.4.1/include -DNDEBUG -I"/home/cd/R/i686-pc-linux-gnu-library/3.4/Rcpp/include" -I/usr/local/include -fpic -g -O2 -flto -c loop_apply.c -o loop_apply.o
clang++ -I/opt/R-3.4.1/include -DNDEBUG -I"/home/isomorphismes/R/i686-pc-linux-gnu-library/3.4/Rcpp/include" -I/usr/local/include -fpic -I/opt/boost_1_61_0/boost -c split-numeric.cpp -o split-numeric.o
clang++ -shared -L/usr/local/lib -o plyr.so RcppExports.o loop_apply.o split-numeric.o
loop_apply.o: file not recognized: File format not recognized
clang: error: linker command failed with exit code 1 (use -v to see invocation)
/opt/R-3.4.1/share/make/shlib.mk:6: recipe for target 'plyr.so' failed
make: *** [plyr.so] Error 1
ERROR: compilation failed for package ‘plyr’
* removing ‘/home/cd/R/i686-pc-linux-gnu-library/3.4/plyr’
The *.o files are in /opt/plyr/src, from github.com/hadley/plyr. They look like this on my system:
i#scheherezade:/opt/plyr/src$ file *o
loop_apply.o: LLVM IR bitcode
RcppExports.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
split-numeric.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
In case you didn't know, -flto specifies link time optimization, and has been added by R. How did you manage to end up with such a mis-configured R install?
Adding -flto to the link command may work? Or remove it from the loop_apply compilation line. If either of those works, you need to fix your R install.
Compiling with -flto using clang requires (on Ubuntu) installing the llvm-dev package. Otherwise, the linker is unable to handle -flto object files.
apt-get install clang-10 llvm-10-dev
Now the linking should succeed.

How can I install topicmodels package in R?

I am trying to install the package called topicmodels in R and I have not had success. Here's what I have tried...
Action:
Install the package using install.packages("topicmodels")
Result:
package ‘topicmodels’ is available as a source package but not as a binary
Warning in install.packages :
package ‘topicmodels’ is not available (for R version 3.1.0)
So there I said okay let's install from source
Action:
install.packages("/Users/my_name/Downloads/topicmodels_0.2-1.tar.gz",repos=NULL,type="source")
Result:
* installing *source* package ‘topicmodels’ ...
** package ‘topicmodels’ successfully unpacked and MD5 sums checked
** libs
clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -fPIC -Wall -mtune=core2 -g -O2 -c cokus.c -o cokus.o
clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -fPIC -Wall -mtune=core2 -g -O2 -c common.c -o common.o
clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -fPIC -Wall -mtune=core2 -g -O2 -c ctm.c -o ctm.o
ctm.c:29:10: fatal error: 'gsl/gsl_rng.h' file not found
include gsl/gsl_rng.h
1 error generated.
make: *** [ctm.o] Error 1
ERROR: compilation failed for package ‘topicmodels’
* removing ‘/Library/Frameworks/R.framework/Versions/3.1/Resources/library/topicmodels’
Warning in install.packages :
installation of package ‘/Users/me/Downloads/topicmodels_0.2-1.tar.gz’ had non-zero exit status
So then I researched this gsl thing and came upon this link. And for the moment I thought all of my problems were gone and when I finally follow these directions. I get the following error (in the terminal)...
Warning in untar2(tarfile, files, list, exdir, restore_times) :
using pax extended headers
ERROR: cannot extract package from ‘topicmodels.tar.gz’
First of all you have to install gsl. Once you have that installed you can try to install the R package. You can download gsl from here (there you can pick the latest version gsl-latest.tar.gz). Once it's been downloaded, install it by doing the following:
Decompress the downloaded file (in my case the "latest" file contained this version: gsl-1.16)
Open the "Terminal"
Then (using the Terminal), move inside the folder that you created on step 1. In my case I had the file on the folder called "Downloads", so I moved to the newly created folder by doing:
cd Downloads/gsl-1.16
Once you are within that folder run the following commands (in order):
./configure
make
sudo make install
After doing it you won't get the previous error saying fatal error: 'gsl/gsl_rng.h' file not found, so you can try again the installation.
Now go back to your R environment (e.g., RStudio) to try again to install the package by doing:
install.packages("PATH_TO_TOPIC_MODELS.tar.gz", repos=NULL, type="source").
I had the same problem, and after doing this I got the R package correctly installed, I hope it also works in your case.
If you already using homebrew. It is better and faster to fix with variables than installing gsl manually from source.
Install gsl with homebrew brew install gsl
Edit ~/.R/Makevars and add.
PKG_LIBS=-L/usr/local/opt/gettext/lib
CFLAGS=-I/usr/local/opt/gsl/include
LDFLAGS=-L/usr/local/opt/gsl/lib -lgsl -lgslcblas
If you are using Linux based on Debian, that's my solution:
Using terminal run sudo apt install gsl-bin libgsl-dbg libgsl-dev libgsl25 libgslcblas0;
Then, using R console, run install.packages("topicmodels",dependencies =T);
Enjoy!!

Resources