-
Notifications
You must be signed in to change notification settings - Fork 37
Compilers and mrgsolve
Current versions of C++ and FORTRAN compilers are required to use mrgsolve. Available compilers and requirements may vary by operating system. Please see system-specific instructions below. In addition to the advice provided here, here is very detailed and complete information on compilers to use with R on the r-project website (https://cran.r-project.org/doc/manuals/R-admin.html and see links below).
If you did install the compilers and still cannot install mrgsolve or compile a model in R, please see the section on testing your compilers. This will give you some simple example code that is independent of mrgsolve that will only run if the compiler is installed properly.
You can also check out the pkgbuild package (https://github.com/r-pkgs/pkgbuild). This package has some functions that will help you diagnose problems with your R build toolchain.
For example, try
install.packages("devtools")
devtools::install_github("r-pkgs/pkgbuild")
check_build_tools()Please post on the issue tracker if you have questions about compiler requirements.
You need to download and properly install the Windows toolset (Rtools). Do not use any compiler other than the one provided by the r-project. You MUST use Rtools. Please update to a recent version even if you think you already have it installed.
You are encouraged to try the installr package to help you install the correct
Rtools package.
install.packages("installr")
install.Rtools()This might work just fine for your installation. If not, please keep reading.
These tips are based on many hours spent helping people install Rtools for Windows properly.
- Read about the Windows toolset
- Especially if things are not working for you, there is important information to be found in this link. If you haven't read this, read it now.
- Download
RtoolsXX.exe-
XXis the version number (e.g.Rtools32.exe) - Get the version number that corresponds to your version of
R - Do not get a version that is not frozen yet; experience has told us that the latest / newest version isn't at all the best
-
- Install
RtoolsXX.exe- When you are installing, pay attention for a prompt asking about changing the
PATH; make sure that the installer updatesPATH
- When you are installing, pay attention for a prompt asking about changing the
- Check your
PATHenvironment variable inR- Use the command
Sys.getenv("PATH")in R, after restarting to make sure the proper directories are listed there.Rwill not find the toolchain unless thePATHis correctly - If
PATHis not properly set, try to set it with a system-wide environment variable - If a system-wide environment variable is not posible, there are some other options here
- Use the command
- Install
Rcpp,RcppArmadillo, andmrgsolveall from source- Do this even if you think you already have them installed; it is important to re-install these packages after installing
Rtools - To install from source:
install.packages(c("Rcpp", "RcppArmadillo"), type="source")
- Do this even if you think you already have them installed; it is important to re-install these packages after installing
- Please see this page for
common error messages you might encounter if
Rtoolsisn't installed correctly.
Installation instructions and download links for Rtools can be found in these links:
- https://cran.r-project.org/doc/manuals/R-admin.html#The-Windows-toolset
- https://cran.r-project.org/bin/windows/Rtools/
Please read carefully. There isn't a lot to read here, but there are clear and easy-to-follow directions about what you need to do directly from the R people.
You can look here for another set of instructions if the advice provided above didn't answer your questions: Rtools install instructions on the rstan github page
A suitable C++ compiler is available in Xcode (https://developer.apple.com/xcode/). Be sure to download and install command line tools (bash$ xcode-select --install). Always use the most up to date version.
Xcode does not include a FORTRAN compiler. There are different FORTRAN compiler requirements for Snow Leopard or Mavericks (or greater) R builds. See the platform-specific FAQs below.
Carefully read the following for information:
There are several options for install a gfortran compiler for macOS. If you are using El Capitan or Sierra,
you need an "alternative" gfortran installation. To our knowledge, this is the only viable option for El Capitan or Sierra users ... so it really should be "standard" now rather than "alternative". There are two
gfortran binaries that you can choose from and there are some extra steps you need to take in writing your
Makevars file too (see below).
For so-called Mavericks builds on older Mac OSX operating systems, we still recommend the gfortran-4.8 as distributed by R folks. This is an older gfortan version, but it is likely what you need for that Mavericks build.
This is a bit of a fluid situation. Please don't hesitate to ask for help on the issue tracker. We'd be happy to help or advise as best as we can.
-
To use an alternative
gfortrancompiler, especially if usingEl CapitanorSierra:- Download a
gfortrancompiler; these compilers are mentioned inRdocumentation as alternatives: - Edit your
HOME/.R/Makevarsfile and setF77to point to the differentgfortrancompiler (see the exampleMakevarsfile here - Here is more information on setting
F77: https://cran.r-project.org/doc/manuals/R-admin.html#Customizing-package-compilation - Example: see issue #116
- Download a
-
gfortranfor Mavericks build:- This
Ris built withgfortran-4.8 - Please note that this is probably not what you want if you are using macOS Sierra or possibly El Capitan
- Link: https://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2
- To install the tarball, run
sudo tar -zxf gfortran-4.8.2-darwin13.tar.bz2 -C /
- This
- We recommend and support using the CRAN binary and toolchain, but we understand that a pure homebrew implementation (
Rand toolchain) has worked.- The key seems to be matching the
homebrewRinstall with thehomebrewgccinstall.
- The key seems to be matching the
- If you are using the
homebrewapproach, please contact personnel from that project for help with compiler issues.
UNIX usually include C++ and FORTRAN compliers. If not, install gcc.
Here is some code that you can run in an R script (in Rstudio) that will help you test if your C++ compiler is properly installed. You should be able to run R CMD SHLIB without any errors.
Get the source code here.
ccode <- 'extern "C" {void test() {double x=2.1; x = x+1;}}\n'
cat(file="R_Cpp_Test.cpp", ccode)
system("R CMD SHLIB R_Cpp_Test.cpp")The output might look like this on Mac:
/usr/bin/clang++ -Wall -O2 -Qunused-arguments -Wpedantic -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 R_Cpp_Test.cpp -o R_Cpp_Test.o
/usr/bin/clang++ -Wall -O2 -Qunused-arguments -Wpedantic -dynamiclib -Wl,-headerpad_max_install_names
-undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib
-L/usr/local/lib -o R_Cpp_Test.so R_Cpp_Test.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework
-Wl,CoreFoundationThe output might look like this on Windows:
c:/Rtools/mingw_64/bin/g++ -I"C:/Users/YSU/R-33~1.1/include" -DNDEBUG
-I"d:/Compiler/gcc-4.9.3/local330/include" -O2 -Wall -mtune=core2 -c R_Cpp_Test.cpp -o R_Cpp_Test.o
c:/Rtools/mingw_64/bin/g++ -shared -s -static-libgcc -o R_Cpp_Test.dll tmp.def R_Cpp_Test.o
-Ld:/Compiler/gcc-4.9.3/local330/lib/x64 -Ld:/Compiler/gcc-4.9.3/local330/lib
-LC:/Users/YSU/R-33~1.1/bin/x64 -lRThe output might look like this on Linux:
g++ -I/usr/share/R/include -DNDEBUG -fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4
-Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c R_Cpp_Test.cpp -o R_Cpp_Test.o
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o R_Cpp_Test.so R_Cpp_Test.o
-L/usr/lib/R/lib -lRNOTE this will be picky about spaces; please download the source code here.
fcode <- '
subroutine bar(n, x)
integer n
double precision x(n)
integer i
do 100 i = 1, n
x(i) = x(i) ** 2
100 continue
end
'
cat(file="R_FORTRAN_Test.f", fcode)
system("R CMD SHLIB R_FORTRAN_Test.f")Result on Mac:
gfortran-4.8 -fPIC -g -O2 -c R_FORTRAN_Test.f -o R_FORTRAN_Test.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module
-multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib
-o R_FORTRAN_Test.so R_FORTRAN_Test.o -L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2
-lgfortran -lquadmath -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework
-Wl,CoreFoundationResult on Windows:
c:/Rtools/mingw_64/bin/gfortran -O2 -mtune=core2 -c R_FORTRAN_Test.f -o R_FORTRAN_Test.o
c:/Rtools/mingw_64/bin/gcc -shared -s -static-libgcc -o R_FORTRAN_Test.dll tmp.def R_FORTRAN_Test.o
-Ld:/Compiler/gcc-4.9.3/local330/lib/x64 -Ld:/Compiler/gcc-4.9.3/local330/lib -lgfortran -lm -lquadmath
-LC:/Users/YSU/R-33~1.1/bin/x64 -lRResult on Linux:
gfortran -fpic -g -O2 -c R_FORTRAN_Test.f -o R_FORTRAN_Test.o
gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o R_FORTRAN_Test.so
R_FORTRAN_Test.o -lgfortran -lm -lquadmath -L/usr/lib/R/lib -lRIf running the simple example code presented here, it means your compiler is not properly installed. Please touch base with us on the issue tracker for help.
The compilers will be used to compile C++ and FORTRAN code inside the mrgsolve package as well as user-created models. It is imperative that mrgsolve be compiled with the same compiler used to compile the user-created model. If different compilers are used, it is likely that a segmentation fault will happen. This behavior would be expected when different compilers are used.