R Packages Fail to Compile with Gcc

R Packages Fail to Compile with gcc

Modify your PATH to make sure that a gcc compiler more recent than gcc 3.2 is found.

If necessary, create a link to the recent one (assuming you want to still keep gcc 3.2 around):

mkdir $HOME/bin
ln -s /usr/bin/gcc-VERSION $HOME/bin/gcc
export PATH=$HOME/bin:$PATH
# proceed to your normal installation

VERSION indicates the gcc version of the compiler normally used in your system

Error installing old packages in R

You should install Rtools which contains resources needed to build packages in R under Microsoft Windows :

https://cran.r-project.org/bin/windows/Rtools/

After installing, you should see it under your PATH variable:

Sys.getenv("PATH")

Override Specific Compiler Flags When Installing R Packages

You can edit your .R/Makevars file and append the desired flags using the += operator, e.g.

CFLAGS+= -O3 -Wall -mtune=native -march=native

The latter flag is used if there is a conflict, as you said in your comment below. In terms of compiling from source, you can do this via install.packages(), e.g.

install.packages("package_name", type = "source")

How to avoid cannot find -lR for R Package installation on windows

You are making three mistakes:

  1. You should not install rtools under program files or any other path with a space.
  2. You are using BINPREF wrong, causing the 64-bit toolchain to be used on 32-bit.
  3. The mingw gcc dirs should not be on the PATH. Only the bin dir (bash and make) should be.

Recommended setup:

It is highly recommended to install rtools in the default location C:\Rtools\. This is the only configuration that is widely tested.

In this case you only need to make put C:\Rtools\bin is on the PATH in order to compile packages. R will automatically use the correct compilers on 32-bit and 64-bit.

With non-default Rtools location:

If you really must install rtools in a non standard location, you can set BINPREF to a pattern that includes $(WIN) that gets expanded to the correct path for example like so:

Sys.setenv(BINPREF="C:/YourRtoolsPath/mingw_$(WIN)/bin/")

When make invokes the compiler, $(WIN) gets substituted by either 32 or 64 which should then resolve to the correct path of the respective toolchain.



Related Topics



Leave a reply



Submit