How to build a Xen unikernel of Mirage OS - xen

I read this document(http://openmirage.org/wiki/hello-world) and tried to build a xen unikernel as follows:
mirage configure --xen
make depend
make
But failed at compilation:
ocamlbuild -classic-display -use-ocamlfind -pkgs lwt.syntax,mirage-console.xen,mirage-types.lwt -tags "syntax(camlp4o),annot,bin_annot,strict_sequence,principal" -tag-line "<static*.*>: -syntax(camlp4o)" -cflag -g -lflags -g,-linkpkg,-dontlink,unix main.native.o
ocamlfind ocamldep -package mirage-types.lwt -package mirage-console.xen -package lwt.syntax -syntax camlp4o -modules main.ml > main.ml.depends
ocamlfind ocamlc -c -g -annot -bin-annot -principal -strict-sequence -package mirage-types.lwt -package mirage-console.xen -package lwt.syntax -syntax camlp4o -o main.cmo main.ml
ocamlfind ocamlopt -c -g -annot -bin-annot -principal -strict-sequence -package mirage-types.lwt -package mirage-console.xen -package lwt.syntax -syntax camlp4o -o main.cmx main.ml
pkg-config --print-errors --exists mirage-xen
Package mirage-xen was not found in the pkg-config search path.
Perhaps you should add the directory containing `mirage-xen.pc'
to the PKG_CONFIG_PATH environment variable
No package 'mirage-xen' found
make: *** [build] Error 1
I installed mirage-xen by opam install mirage-xen successfully.
But in my .opam directory, there are no mirage-xen.pc.

They should appear in your OPAM prefix. I get:
$ ls $(opam config var prefix)/lib/pkgconfig
gmp.pc mirage-xen-ocaml-bindings.pc mirage-xen-posix.pc
libminios-xen.pc mirage-xen-ocaml.pc openlibm.pc
mirage-xen-minios.pc mirage-xen.pc
(you may have fewer; mirage-xen.pc is the important one)
Assuming they're there, check the project's Makefile is setting PKG_CONFIG_PATH correctly.

Chances are that your version of mirage-xen is out of date. You can update it via OPAM by:
opam update -u
opam info mirage-xen
Make sure that you have mirage-xen version 2.1.1 or greater (the latest as of this comment is 2.1.3).
If you don't pick up the upgrade, then you may have a local Git checkout of the central package database. Confirm this by looking at the output of:
opam remote
The output of this should tell you where your local git checkout is, and so navigate there and refresh from git://github.com/ocaml/opam-repository and then run opam update -u.

Related

Installing R on OSX Big Sur (EDIT: and Apple M1) for use with Rcpp and openMP

There's probably a gazillion threads on OSX+Rcpp+openMP, but the bottom line right now appears to be this (per coatless):
Unfortunately, with R 4.0.0 the CRAN distributed version of R loses
the ability to use OpenMP without a custom setup.
I came across other ideas, including compiling llvm yourself, using homebrew or macports to install R and/or llvm and/or gcc, and then figuring out how to use the right compiler and/or flags with (R)cpp. However, I find this all very confusing.
I am not a mac user, but it seems to me that setting up a mac to compile Rcpp packages or code snippets with openMP seems to be too difficult for most mac users. However, I would like my R package on github to be used by more users, and since it relies on openMP, I am losing that audience.
Can someone provide the necessary steps to set up R on mac in a way that it can compile Rcpp code with openMP? I'd like to turn that into a quick tutorial.
EDIT: I should have added - on Apple Silicon, because there are some extra confusions where things go - /usr/local vs /opt
I spent a day figuring this out (original post here); here are the steps I used to compile R packages from source with openMP:
Install xcode from the app store (instructions for installing xcode) then install/reinstall the xcode command line tools from the terminal:
# To delete an existing command line tools installation:
sudo rm -rf /Library/Developer/CommandLineTools
# To install the command line tools
sudo xcode-select --install
Install gcc via Homebrew (instructions for installing Homebrew) or, if you already have gcc installed, skip to step 3.
# WARNING: This can take several hours
brew install gcc
To avoid "legacy" version issues:
brew cleanup
brew update
brew upgrade
brew reinstall gcc
Link some headers into /usr/local/include
sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/
# You can ignore warnings like this:
#ln: /usr/local/include//tcl.h: File exists
#ln: /usr/local/include//tclDecls.h: File exists
#ln: /usr/local/include//tclPlatDecls.h: File exists
#ln: /usr/local/include//tclTomMath.h: File exists
#ln: /usr/local/include//tclTomMathDecls.h: File exists
#ln: /usr/local/include//tk.h: File exists
#ln: /usr/local/include//tkDecls.h: File exists
#ln: /usr/local/include//tkPlatDecls.h: File exists
Check your version of gfortran (cd /usr/local/gfortran/lib/gcc/x86_64-apple-darwin19/; ls) then edit your ~/.R/Makevars file (if you don't have a file called Makevars in your ~/.R/ directory) and include only these lines:
LOC = /usr/local/gfortran
CC=$(LOC)/bin/gcc -fopenmp
CXX=$(LOC)/bin/g++ -fopenmp
CXX11 = $(LOC)/bin/g++ -fopenmp
CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L$(LOC)/lib -Wl,-rpath,$(LOC)/lib
CPPFLAGS=-I$(LOC)/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
# (check that the version of gfortran - in this case 10.2.0 - matches the version specified in FLIBS)
FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin19/10.2.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm
CXX1X=/usr/local/gfortran/bin/g++
CXX98=/usr/local/gfortran/bin/g++
CXX11=/usr/local/gfortran/bin/g++
CXX14=/usr/local/gfortran/bin/g++
CXX17=/usr/local/gfortran/bin/g++
Open R and install a package to test that it compiles with openMP enabled (when asked, compile from source = "Yes"):
install.packages("data.table", type = "source")
Unfortunately, I do not believe a more "simple" setup exists.
Eventually, I found a process that works on a M1 mac with Big Sur.
Head over to https://mac.r-project.org/, it contains most things you will need
Download and install R via R-4.1-branch.pkg. The CRAN version might also work, but I used the installer from mac.r-project.org, which required opening the osx security settings to allow the installation.
Install RStudio, start it, and let it install the developer tools. Alternatively, run sudo xcode-select --install in Terminal.
Head to https://mac.r-project.org/openmp/. Download openmp-11.0.1-darwin20-Release.tar.gz and install it (see Terminal commands below).
curl -O https://mac.r-project.org/openmp/openmp-11.0.1-darwin20-Release.tar.gz
sudo tar fvx openmp-11.0.1-darwin20-Release.tar.gz -C /
Now we need to add compiler flags so that clan uses openMP. In Terminal, create the Makevars file.
cd ~
mkdir .R
nano .R/Makevars
in nano, paste these additional compiler flags into the Makevars file:
CPPFLAGS += -Xclang -fopenmp
LDFLAGS += -lomp
Hit Control+O, Control+X to save and close
Head over to the gfortran page: https://github.com/fxcoudert/gfortran-for-macOS/releases
Use the installer gfortran-ARM-11.0-BigSur.pkg to install gfortran.
For some reason it appears to install in /usr/local/gfortran, but R expects it in /opt. The mac-R team likes to separate arm64 and intel related files. We could go and fix paths, or simply also install gfortran under /opt. Download the tar file gfortran-ARM-11.0-BigSur.tar.xz. You can use curl, or just download it and point tar in the command line to it.
cd /opt/R/arm64/
sudo mkdir gfortran
sudo tar -xzyf gfortran-ARM-11.0-BigSur.tar.xz -C /opt/R/arm64/
(replace gfortran-ARM-11.0-BigSur.tar.xz with /users/YOURUSERNAME/downloads/gfortran-ARM-11.0-BigSur.tar.xz)
Now it should work.
Not an expert in OSX, but doing this so others can figure out how to use my R package. I'd like to streamline the process some more, but wiping the mac, reinstalling osx and testing it takes so much time.

Installation of rJava

I've tried to solve this using the previous questions/answers on SO but without any success. So, here's my problem.
I'm using RStudio on and Ubuntu box (14.04) and I tried to upgrade rJava from sources and in the process I managed to lose it.
I tried to install it again using,
install.packages("rJava")
which returned the following error message,
configure: error: One or more Java configuration variables are not set.
Make sure R is configured with full Java support (including JDK). Run
R CMD javareconf
as root to add Java support to R.
If you don't have root privileges, run
R CMD javareconf -e
to set all Java-related variables and then install rJava.
ERROR: configuration failed for package ‘rJava’
* removing ‘/home/darren/R/x86_64-pc-linux-gnu-library/3.2/rJava’
Warning in install.packages :
installation of package ‘rJava’ had non-zero exit status
So, I went to the terminal and typed,
sudo R CMD javareconf
which also gave the following error,
trying to compile and link a JNI program
detected JNI cpp flags :
detected JNI linker flags : -L/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server -ljvm
gcc -std=gnu99 -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 conftest.c -o conftest.o
conftest.c:1:17: fatal error: jni.h: No such file or directory
#include <jni.h>
^
compilation terminated.
make: *** [conftest.o] Error 1
Unable to compile a JNI program
JAVA_HOME : /usr/lib/jvm/default-java
Java library path:
JNI cpp flags :
JNI linker flags :
Updating Java configuration in /usr/lib/R
Done.
I tried to follow these links, one and two but they didn't seem to resolve my issue; there are more links on SO but I'm not sure which one to follow. I've also un-installed and re-installed RStudio via the Ubuntu Software Centre but this didn't make any difference.
Can anyone else help?
In short, I want to be able to use RStudio with rJava again without it destroying any other uses of Java (such as jmol).
You don't seem to have JDK installed. You will need at least
sudo apt-get install openjdk-7-jdk
then re-run
sudo R CMD javareconf
Make sure you do NOT set JAVA_HOME by hand - it will be detected automatically. You should then see something like this:
$ sudo R CMD javareconf
Java interpreter : /usr/bin/java
Java version : 1.7.0_91
Java home path : /usr/lib/jvm/java-7-openjdk-amd64/jre
Java compiler : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
trying to compile and link a JNI program
detected JNI cpp flags : -I$(JAVA_HOME)/../include
detected JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -I/usr/lib/jvm/java-7-openjdk-amd64/jre/../include -fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c conftest.c -o conftest.o
gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o conftest.so conftest.o -L/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server -ljvm -L/usr/lib/R/lib -lR
JAVA_HOME : /usr/lib/jvm/java-7-openjdk-amd64/jre
Java library path: $(JAVA_HOME)/lib/amd64/server
JNI cpp flags : -I$(JAVA_HOME)/../include
JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
What is wrong with sudo apt-get install r-cran-rjava ?
See for example this earlier answer and the question / thread around it.
For an installation from scratch, you could still much worse than starting from sudo apt-get build-dep r-cran-rjava. It will get you the JDK corresponding to your Ubuntu version.
First i would recommend installing Rstudio from its website: https://www.rstudio.com/products/rstudio/download/ (i.e. Rstudio 64bit: https://download1.rstudio.org/rstudio-0.99.489-amd64.deb). This does not solve the problem directly, but it helps to avoid other bugs with Rstudio.
Regarding the error, trying to make sure you have JDK install. I don't think the command java -version can tell if JDK is installed. You have to check the package of JDK itself, or based on the error message, do this:
locate jni.h
The output should match or compatible with your JAVAHOME, e.g:
/usr/lib/jvm/java-7-openjdk-amd64/include/jni.h
/usr/lib/jvm/java-7-oracle/include/jni.h
Update 1:
R CMD javareconf is looking for the jni.h file under $(JAVA_HOME)/include
You have JDK installed, but it is very likely that you are having default java to a JRE directory, that why the error happened.
You can see where default-java is really pointing to by doing this command:
jRealDir=$(readlink -f /usr/lib/jvm/default-java)
echo $jRealDir
# sample correct output: /usr/lib/jvm/jdk1.8.0_65
# or /usr/lib/jvm/java-8-oracle if you default to Oracle's
# now check jni.h
ls -l $jRealDir/include/jni.h
# sample expected output:
# /usr/lib/jvm/jdk1.8.0_65/include/jni.h
If the ls command failed, you have to setup so that javareconf ( and later rJava) can use the java from JDK not from JRE. You have two options:
Method 1: Do it system-wide
This is convenient, but may effect other program like the one you mentioned jmol. But don't worry, this is revertible, just re-run the command and pick the old one. Do the following command and pick the dir that has JDK:
sudo update-alternatives --config java
After that test how jmol works, if it works alright then congrat. You are now ready to test rJava. If not, try the second method below
Method 2: Do it for R only
put this in the .Rprofile under your home directory
Sys.setenv(JAVA_HOME = '/usr/lib/jvm/jdk1.8.0_65')
# this set JAVA_HOME for R to correct java home dir.
After updating or creating the .Rprofile DO restart R in Rstudio. The R CMD javareconf may still fail in this case, but it should be OK if you run it from Shell under Tools menu of Rstudio.
Regarding the installing or Rstudio from Ubuntu's stock repo. It would not make a difference for getting rJava running. Then again, I recommend installing Rstudio for its homepage because new version also has some nice features (i.e. better autocompletion, which I like the most).
Here is link on R-Bloggers that worked for me: https://www.r-bloggers.com/installing-rjava-on-ubuntu/
sudo apt-get install -y default-jre
sudo apt-get install -y default-jdk
sudo R CMD javareconf
install.packages("rJava")
I've been dealing with this exact issue, nothing in this thread or other that are similar have solved it. I'm on Ubuntu 16.04, here's how I got it to work:
apt-get install openjdk-9-jdk
rm -rf /usr/lib/jvm/default-java
ln -s /usr/lib/jvm/java-9-openjdk-amd64/ /usr/lib/jvm/default-java
You can see where the JAVA_HOME is in the error message.
Then use locate jni.h to find where is jni.h, next use soft link to link this location to $(JAVA_HOME)/include, just like #biocyberman mentioned.
This is what I did:
ln -s /usr/lib/jvm/java-8-openjdk-amd64/include/jni.h /opt/conda/include/jni.h
ln -s /usr/lib/jvm/java-8-openjdk-amd64/include/linux/jni_md.h /opt/conda/include/jni_md.h
ln -s /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so /usr/lib/
Since my JAVA_HOME is /opt/conda and I also don't have jni_md.h and -ljvm.
I am use Ubuntu 16.04.

Install R from source

I'm trying to install R from source in my home directory on a server running CentOS.
I do not have root rights, and I'm not permitted to write to `usr/local/include/'.
I use the following code:
wget http://cran.rstudio.com/src/base/R-3/R-3.2.0.tar.gz
tar xvf R-3.2.0.tar.gz
cd R-3.2.0
./configure --prefix=$HOME/R
In configuration step, I get error
configure:error:--with-readline=yes (default) and headers/libs are not available
In my understanding, it tells me that readline library is not available.
So I try to install readline.
I downloaded tar.gz file. and then I use the following command
tar xvf readline-6.3.tar.gz
cd readline-6.3
./configure --prefix=$HOME/readline
make
make install
Things are fine, and there's an additional folder in my home directory named "readline".
When I go back and try to configure R again, I still get the same error message. How can I fix it?
Try using these flags for your ./configure script
CXXFLAGS="-ggdb -pipe -Wall -pedantic -I/path/readline/6.3/include"
CPPFLAGS="-I/path/readline/6.3/include"
LDFLAGS="-L/path/readline/6.3/lib"
Then if you get an error about X11, set --with-x=no and try again.

Installing package failed when trying to run to application to Meego

I'm trying to run a Hamattan Application on a Meego Device, but everytime I try to run it into the Meego device:
:-1: error: Installing package failed.
always appears. But sometimes when I check my phone the application is there and it's running.
In Settings->Applications->Manage Applications it says there:
Test2
Installation Failed
Please Help me. Thank you very much!
Compile Output:
Running build steps for project test2...
Configuration unchanged, skipping qmake step.
Starting: "C:\qtsdk\madde\bin\make.exe" -w
make: Entering directory `/c/Users/bcue/Qt/test2'
make: Nothing to be done for `first'.
make: Leaving directory `/c/Users/bcue/Qt/test2'
The process "C:\qtsdk\madde\bin\make.exe" exited normally.
Creating package file ...
Package Creation: Running command 'c:/qtsdk/madde/bin/mad dpkg-buildpackage -nc -uc -us'.
dpkg-buildpackage: set CFLAGS to default value: -g -O2
dpkg-buildpackage: set CPPFLAGS to default value:
dpkg-buildpackage: set LDFLAGS to default value:
dpkg-buildpackage: set FFLAGS to default value: -g -O2
dpkg-buildpackage: set CXXFLAGS to default value: -g -O2
dpkg-buildpackage: source package test2
dpkg-buildpackage: source version 0.0.1
dpkg-buildpackage: source changed by unknown <>
dpkg-buildpackage: host architecture armel
which: pgp: unknown command
debian/rules build
make: Nothing to be done for `build'.
debian/rules binary
dh_testdir
dh_testroot
dh_clean -k
dh_installdirs
# Add here commands to install the package into debian/test2.
/usr/bin/make INSTALL_ROOT="/c/Users/bcue/Qt/test2"/debian/test2 install
make[1]: Entering directory `/c/Users/bcue/Qt/test2'
install -m 644 -p c:/Users/bcue/Qt/test2/test2.desktop /c/Users/bcue/Qt/test2/debian/test2/usr/share/applications/
install -m 644 -p c:/Users/bcue/Qt/test2/test2.png /c/Users/bcue/Qt/test2/debian/test2/usr/share/icons/hicolor/64x64/apps/
install -m 755 -p "test2" "/c/Users/bcue/Qt/test2/debian/test2/opt/test2/bin/test2"
make[1]: Leaving directory `/c/Users/bcue/Qt/test2'
sed 's:^Icon=.*:Icon=/usr/share/icons/hicolor/64x64/apps/test2.png:' /C/Users/bcue/Qt/test2/debian/test2/usr/share/applications/test2.desktop > /C/Users/bcue/Qt/test2/debian/test2/usr/share/applications/test2.desktop.sed || echo -n
mv /C/Users/bcue/Qt/test2/debian/test2/usr/share/applications/test2.desktop.sed /C/Users/bcue/Qt/test2/debian/test2/usr/share/applications/test2.desktop || echo -n
sed 's:Exec=.*:Exec=/opt/test2/bin/test2:' /C/Users/bcue/Qt/test2/debian/test2/usr/share/applications/test2.desktop > /C/Users/bcue/Qt/test2/debian/test2/usr/share/applications/test2.desktop.sed || echo -n
mv /C/Users/bcue/Qt/test2/debian/test2/usr/share/applications/test2.desktop.sed /C/Users/bcue/Qt/test2/debian/test2/usr/share/applications/test2.desktop || echo -n
dh_testdir
dh_testroot
dh_installchangelogs
dh_installdocs
dh_installexamples
dh_installman
dh_link
dh_strip
dh_compress
dh_fixperms
dh_installdeb
dh_shlibdeps
dh_gencontrol
dpkg-shlibdeps: warning: dependency on libgcc_s.so.1 could be avoided if "debian/test2/opt/test2/bin/test2" were not uselessly linked against it (they use none of its symbols).
dpkg-shlibdeps: warning: dependency on libmdeclarativecache.so.0 could be avoided if "debian/test2/opt/test2/bin/test2" were not uselessly linked against it (they use none of its symbols).
dpkg-shlibdeps: warning: dependency on libpthread.so.0 could be avoided if "debian/test2/opt/test2/bin/test2" were not uselessly linked against it (they use none of its symbols).
dpkg-gencontrol: warning: unknown substitution variable ${misc:Depends}
dh_md5sums
dh_builddeb
a - debian-binary
a - control.tar.gz
a - data.tar.gz
dpkg-buildpackage: binary only upload (no source included)
Use of uninitialized value in undef operator at /madbin/dpkg-buildpackage line 369.
dpkg-genchanges -b -u.. >../test2_0.0.1_armel.changes
dpkg-genchanges: binary-only upload - not including any source code
Package created.
Installing package to sysroot ...
c:\Users\bcue\Qt\qt-components-qt-components\C;c:\qtsdk\madde\Users\bcue\Qt\test2\test2_0_0_1_armel.deb: No such file or directory
c:\qtsdk\madde\targets\harmattan-nokia-meego-api\bin\ar.exe:
Cannot find package name (in debian control file).
Connecting to device...
Started uploading file 'C:\Users\bcue\Qt\test2\test2_0_0_1_armel.deb'.
Successfully uploaded file 'C:\Users\bcue\Qt\test2\test2_0_0_1_armel.deb'.
Installing package to device...
warning, in file '/var/lib/dpkg/status' near line 663 package 'mp-harmattan-rm680-pr':
missing description
(Reading database ...
29097 files and directories currently installed.)
Preparing to replace test2 0.0.1 (using .../test2_0_0_1_armel.deb) ...
Unpacking replacement test2 ...
aegis-installing test2 (from 'com.nokia.maemo')
dpkg: dependency problems prevent configuration of test2:
test2 depends on libqt4-declarative (>= 4.7.4~git20110516); however:
Version of libqt4-declarative on system is 4.7.3~git20110329-0maemo1+0m6.
test2 depends on libqtcore4 (>= 4.7.4~git20110516); however:
Version of libqtcore4 on system is 4.7.3~git20110329-0maemo1+0m6.
test2 depends on libqtgui4 (>= 4.7.4~git20110516); however:
Version of libqtgui4 on system is 4.7.3~git20110329-0maemo1+0m6.
dpkg: error processing test2 (--install):
dependency problems - leaving unconfigured
Processing triggers for desktop-file-utils ...
Errors were encountered while processing:
test2
Deployment failed.
Error while building project test2 (target: Harmattan)
When executing build step 'Deploy to Harmattan device'
did you updated your Qt Creator? (2.3.1 if I'm not wrong)
the update bring along the updated SDK for the meego harmattan,.
in that case you should also update your meego phone too because there's some dependency for the newest library. (read the error, dependency-problem)
check here for the update package
http://www.developer.nokia.com/search/search.xhtml?view=ebs&hv=fn:type%3DfnType:Terminal&s=ft&tl=0&ob=best&me=false&l=20&expandDoc=false&k=N950+device+update&oldK=N950+device+update
this one problem makes me revert my QtCreator to the old one , I'm not allowed to upgrade the phone. duh

Building R package and error "ld: cannot find -lgfortran"

I'm trying to install the package lars. Ubuntu 11.04 Natty 64-bit. From building I get:
* installing *source* package âlarsâ ...
** libs
gfortran -fpic -O3 -pipe -g -c delcol.f -o delcol.o
gcc -shared -o lars.so delcol.o -lgfortran -lm -L/usr/lib64/R/lib -lR
/usr/bin/ld: cannot find -lgfortran
collect2: ld returned 1 exit status
make: *** [lars.so] Error 1
ERROR: compilation failed for package âlarsâ
gfortran is installed and when I run gfortran --version I get
gfortran --version GNU Fortran
(Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2
sudo ldconfig -v gives the error
/sbin/ldconfig.real: Cannot stat /usr/lib/libgfortran.so: No such file or directory
I have already removed and reinstalled gfortran. What do I need to fix this?
I had the same problem when trying to install the CRAN package VGAM on Ubuntu 12.10 64bit. I already had r-base-dev installed, but Andrew Redd's second comment to Dirk Eddelbuettel's answer worked for me.
Specifically, I was getting two errors:
/usr/bin/ld: cannot find -lgfortran
/usr/bin/ld: cannot find -lquadmath
Which were fixed by the lines:
sudo ln -s /usr/lib/x86_64-linux-gnu/libgfortran.so.3 /usr/lib/libgfortran.so
sudo ln -s /usr/lib/x86_64-linux-gnu/libquadmath.so.0 /usr/lib/libquadmath.so
Note that only the first line would be necessary to take care of the problem from the original post. The second line fixed of my additional error with lquadmath.
For the Debian / Ubuntu family, we usually recommend
$ sudo apt-get install r-base-dev
as it pulls in all packages commonly needed for compiling. And this approach gets tested all the time as the automated package builders rely on this (as well as additional per-package Build-Depends). The gfortran package is listed here too; maybe you have a broken link from a prior installation so I'd also try dpkg --purge gfortran; apt-get install gfortran. That said, dozens of R packages (and R itself) use Fortran so there should not be any magic here.
It looks like other suggestions already fixed your problem, but your question also applied to me but the solution was different in my case. My problem was that my gcc and g++ versions differed from my gfortran version. I used the following to switch them so that they were all the same.
Check what version of gcc, g++, and gfortran you have:
g++ --version
gcc --version
gfortran --version
Match them so that they are all the same:
sudo update-alternatives --config g++
sudo update-alternatives --config gcc
sudo update-alternatives --config gfortran
In my case, I only had one version of gfortran so I simply changed the g++ and gcc versions to match that of gfortran.
I use Centos and I can't get r-base-dev. I have also installed gfortran and its version matches that of gcc and g++; it still didn't work. However, I solved this problem by creating ~/.R/Makevars, using
cd ~
mkdir .R
touch Makevars
I found the directory where I installed gfortran (apparently the problem is that R can't find it) by
which gfortran
It said I installed gfortran in usr/bin/gfortran.
Then I added flags to .R/Makevars to tell R to use:
F77 = /usr/bin/gfortran
FC = $F77
FLIBS = -L/usr/bin/gfortran
You can edit the Makevars file this way:
vi .R/Makevars
Now you have entered the vi program that can edit text files. Type i to edit; you will see INSERT by the bottom of the terminal window. Then you can input what I put above. To save the changes and quit vi, press the esc key, and type :wq.
I'm not totally sure if I put the FLIBS line correctly, since it's very different for MacOS. In MacOS, there's a directory under gfortran that has the libraries to link to, but apparently gfortran is not a directory in linux. At least this worked for me, and also solved the problem of /usr/bin/ld: cannot find -lquadmath, so I installed R packages requiring gfortran smoothly.
Same problem installing R package minqa on ubuntu 12.04, R3.1.0., an x86 32bits (actually it was part of the caret package installation).
Solved by
sudo ln -s /usr/lib/i386-linux-gnu/libgfortran.so.3 /usr/lib/libgfortran.so
r-base-dev reinstall didn't work and I didn't try to re-install gfortran because of all the dependencies.
Depending on the system/version,
ls -l /usr/lib/libgfortran.so
checks that the link exists/is right.
For anyone who reaches this page with the same error on a Mac, try the following:
Install Homebrew and run:
brew install gcc
Then, create a file ~/.R/Makevars with the contents (being mindful that this corresponded to gcc version 9.1.0):
VER=-9
CC=gcc$(VER)
CXX=g++$(VER)
CFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
CXXFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
FLIBS=-L/usr/local/Cellar/gcc/9.1.0/lib/gcc/9
R v3.6.0
gcc v9.1.0
Homebrew v2.1.6
macOS v10.14.5
Just leaving this here for future reference as in my case (Amazon Linux EC2 AMI) the issue was merely with the naming of the symbolic link and not with its location.
sudo ln -s /usr/lib64/libgfortran.so.3 /usr/lib64/libgfortran.so
sudo ln -s /usr/lib64/libquadmath.so.0 /usr/lib64/libquadmath.so
I didn't have to install any libraries. Posting what worked for me, maybe it will be useful for someone.
I had ~/.R/Makevars defining to use CC=gcc-8.
Default gcc on my machine is 7.4.0, but I installed gcc-8.
At the same time I didn't have gfortran 8, but only 7.4.0.
Commenting out the line in Makevars makes compilation fall back to use default gcc-7, and it was successfully using gfortran-7 lib then.
If you are using gcc44, you'll need:
yum install gcc44-gfortran
For future lost souls, it also helps to verify compiler versions all match (per https://askubuntu.com/questions/276892/cannot-find-lgfortran). In my case gcc and gfortran were both 4.8.4, but g++ was 4.6.
As a follow-on to Megatron's answer for Mac homebrew, I had a similar problem with dependencies:
ERROR: configuration failed for package ‘openssl’
removing ‘/usr/local/lib/R/4.1/site-library/openssl’
Warning in install.packages :
installation of package ‘openssl’ had non-zero exit status
just typed brew install openssl into bash and it worked on next packages.install.

Resources