Error installing R/igraph unable to load shared object ‘../’: cannot open shared object file: No such file or directory


I ran into this tiny error that could have consumed my whole day. I had set up an AWS ubuntu 16.04 (Xenial) image and installed R. I think I followed some random web page and ended up installing the latest version of R v3.4.2

I was trying to install this package “`phangorn“` which has igraph as it’s dependency and lo behold, i could not install it kept failing with this error:


Google turned up a few links that seemed to be helpful including installing libxml2-dev

The link below helped me first trouble shoot the foreign-graphml error

 igraph_hacks_internal.h:42:0: warning: "strdup" redefined
In file included from /usr/include/string.h:630:0, from src/foreign-gml-parser.y:54: /usr/include/x86_64-linux-gnu/bits/string2.h:1291:0: note: this is the location of the previous definition

gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -DUSING_R -I. -Iinclude -Ics -Iglpk -Iplfit -ICHOLMOD/Include -IAMD/Include -ICOLAMD/Include -ISuiteSparse_config -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -DNDEBUG -DNPARTITION -DNTIMER -DNCAMD -DNPRINT -DPACKAGE_VERSION=\"1.1.1\" -DINTERNAL_ARPACK -DIGRAPH_THREAD_LOCAL=/**/ -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c foreign-graphml.c -o foreign-graphml.o foreign-graphml.c
: In function ‘igraph_write_graph_graphml’: foreign-graphml.c:1408:46:
 error: expected ‘)’ before ‘GRAPHML_NAMESPACE_URI’ ret=fprintf(outstream, "\n"); 
/usr/lib/R/etc/Makeconf:159: recipe for target 'foreign-graphml.o' failed make: 
[foreign-graphml.o] Error 1 ERROR: compilation failed for package ‘igraph’
removing ‘/home/ubuntu/R/x86_64-pc-linux-gnu-library/3.4/igraph’

ERROR: dependency ‘igraph’ is not available for package ‘phangorn’

removing ‘/home/ubuntu/R/x86_64-pc-linux-gnu-library/3.4/phangorn’

The downloaded source packages are in ‘/tmp/Rtmp7mCd4h/downloaded_packages’
Warning messages: 
1: In install.packages("phangorn", repos = "") : installation of package ‘igraph’ had non-zero exit status 
2: In install.packages("phangorn", repos = "") : installation of package ‘phangorn’ had non-zero exit status

However, they all did not seem to be address the second round of errors where ever after compiling, the failed to load.

Turns out it was a simple thing to fix. The key is to recognize that the second line of the error message was the culprit, even though it does not actually throw an error cannot open shared object file: No such file or directory

There was no installed on my machine and this is not available by default on Xenial.

ubuntu@ip-172-31-93-178:/usr/local/lib$ find /usr -name "libgfortran*"

However, the R version I had installed was somehow compiled with this version and further investigation reveraled that this was basically part of the gcc-7 toolchain. So, for my purposes I installed gcc-7 and gfortran-7 from a ‘ppa’ on ubuntu based on this SO post and this post. So I added the ppa:jonathonf/gcc-7.1 as specified in one of the comments and then installed as follows

sudo apt-get install gcc-7 g++-7 gfortran-7

the gfortran-7 is key as that is what installs the gfortran command and Voila!!! now I can install igraph.

Hope this is helpful to someone out there. #+END_SRC