Cannot find -l<library> R

Using Linux Mint 18.3 (Ubuntu 16.04)

I am using R studio 1.1.383 with R 3.4.2 in the Anaconda environment and I am getting what appears to be compiler errors when trying to install a number of different libraries.

For example, when trying to install "lmtest" (a dependency of "tidyquant", which installed effortlessly on my windows machine) I get the following errors. Since tidyquant had so many dependencies I want to spare you the multiple error messages.

install.packages('lmtest')
trying URL 'https://cran.rstudio.com/src/contrib/lmtest_0.9-35.tar.gz'
Content type 'application/x-gzip' length 183575 bytes (179 KB)
==================================================
downloaded 179 KB

installing *source* package ‘lmtest’ ...
package ‘lmtest’ successfully unpacked and MD5 sums checked
libs

/home/mikejames/anaconda3/bin/x86_64-conda_cos6-linux-gnu-gfortran   -fpic  -fopenmp -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -I/home/mikejames/anaconda3/include -L/home/mikejames/anaconda3/lib  -c pan.f -o pan.o

/home/mikejames/anaconda3/bin/x86_64-conda_cos6-linux-gnu-cc -shared -L/home/mikejames/anaconda3/lib/R/lib -Wl,-O2,--sort-common,--as-needed,-z,relro,-z,now -L/home/mikejames/anaconda3/lib -o lmtest.so pan.o -lgfortran -lm -lgomp -lquadmath -lpthread -L/home/mikejames/anaconda3/lib/R/lib -lR

/home/mikejames/anaconda3/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.2.0/../../../../x86_64-conda_cos6-linux-gnu/bin/ld: cannot find -lgomp

/home/mikejames/anaconda3/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.2.0/../../../../x86_64-conda_cos6-linux-gnu/bin/ld: cannot find -lquadmath

/home/mikejames/anaconda3/lib/R/share/make/shlib.mk:6: recipe for target 'lmtest.so' failed

make: *** [lmtest.so] Error 1

ERROR: compilation failed for package ‘lmtest’
* removing ‘/home/mikejames/anaconda3/lib/R/library/lmtest’
Warning in install.packages :
  installation of package ‘lmtest’ had non-zero exit status

The downloaded source packages are in
    ‘/tmp/RtmpBzLASQ/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done

The common error messages in all my error messages seems to be: cannot find -lgomp and -lquadmath

/home/mikejames/anaconda3/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.2.0    /../../../../x86_64-conda_cos6-linux-gnu/bin/ld: cannot find -lgomp
/home/mikejames/anaconda3/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.2.0    /../../../../x86_64-conda_cos6-linux-gnu/bin/ld: cannot find -lquadmath

Any help would be greatly appreciated!

Upvotes: 1

Views: 1060

Answers (1)

Patrick B.
Patrick B.

Reputation: 484

Using anaconda/miniconda with R may unfortunately be necessary if, for example, you're working with large pipelines like QIIME2 that have a very large and specific set of dependencies in both Python and R. (Edited to add: conda is also useful in general for running stuff on a cluster where you don't have root access, but might need access to specific system libraries that are not installed.) I know this question is quite old, but it is still coming up in search results, so I figured it would be useful to provide some things that have worked for me when I've had to work under these constraints:

  1. Try installing the package through conda install instead of using install.packages. The conda documentation suggests that you use conda search -f r-[pkgname] to find installation candidates. The r channel may be particularly helpful. This is probably the easiest way to go, but may involve some tedious "whack-a-mole" if you have a lot of packages to install and you're getting errors in lots of their dependencies.
  2. Take a look at the compilation errors you're getting and then make sure the necessary libraries are actually installed through conda. "Cannot find -lgomp" suggests that OpenMP needs to be installed; you can do this with conda install -c conda-forge libgomp.
  3. In case step 2 still doesn't work, ld may be looking in the wrong place for your library (even though it should be getting LDFLAGS from your conda environment). This happened to me with libgomp. Inspired by this question's answers I tried manually creating a soft link in my environment's lib folder: ln -s ~/miniconda3/lib/libgomp.so ~/miniconda3/envs/qiime2-2020.6/x86_64-conda-linux-gnu/lib/. That worked and the package installed normally with install.packages().

Instead of step 3, I suppose you could also try adding -L [/your/home/directory]/miniconda3/lib to your LDFLAGS environment variable, which might be more elegant, but you would have to find a way to do so every time you activated the environment. Since I had a working solution at this point I didn't explore this further.

Hope these answers help.

Upvotes: 3

Related Questions