Solve ld linker issues for building R source - r

While trying to install R from source, I ran into linker issues, in particular: undefined reference to 'u_getVersion_58
I found limited information on this error (eg, this post on the RStudio forum).
Despite running apt-get build-dep, these issues persisted.
It is apparent from these comments by Dirk Eddenbuettel that it relates to libicu versions. I have libicu version 60, while R 3.6.0 and similar recent versions seem to require version 58.

We can install a previous version of libicu from source as follows:
wget http://download.icu-project.org/files/icu4c/58.2/icu4c-58_2-src.tgz
tar -xf icu4c-58_2-src.tgz
cd icu
make
make install
However, make is likely to run into a compilation error due to missing xlocale.h. As indicated on this github post, this can be solved by running ln -s /usr/include/locale.h /usr/include/xlocale.h, as xlocale.h is just a subset of locale.h which was removed from glibc recently. After this, make and make install should succeed for icu version 58, and following that, for R.

Related

Cannot install any R package

I'm on Ubuntu 20.04. R version 4.0.2.
I've been using R for a long time and everything worked fine.
Today, when trying to install new packages i get this error:
** checking absolute paths in shared objects and dynamic libraries
readelf: symbol lookup error: readelf: undefined symbol: ctf_arc_bufopen, version LIBCTF_1.0
Error in system(paste("readelf -d", shQuote(l)), intern = TRUE) :
error in running command
I tried to delete and reinstall R and all the packages, but now the same thing happens also for packages that were previously installed. So i think that the problem is not caused by R itself.
I havent done any R update recently.
First of all, thank you very much Chris for hinting at the problem. It was actually ctf-suite related.
When doing grep libctf* it returned:
ii libctf0:amd64 2.35.1-1ubuntu1
amd64 Compact C Type Format library (runtime, BFD dependency)
So I tried:
sudo apt-get install libctf-nobfd0
and it actually solved the problem.
I managed to install all the needed packages.

Installing R-devel via homebrew?

Is it possible to install the current R-devel version via homebrew?
I have already tried brew install --devel r, which does not work.
The reason is indicated in the error message Error: No devel block is defined for r. If you run brew edit r you'll note there is no devel code block indicating the necessary url for the requested development version. Alternatively, you can append the --HEAD flag which will install the most recent r version with the latest commits available in the source repo. The difference between --devel and --HEAD flags is discussed in the Homebrew formula cookbook. Similar info is also discussed here.

zlib/bz2 library and headers are requried for compiling R

Trying to compile R-3.3.2 on Debian Jessie, all dependencies are installed. However the ./configure script complains about the zlib/bzip2 library versions not matching with the minimum requirement.
Minimum version required:
zlib: 1.2.6 (installed version: 1.2.11)
bzip2: 1.0.6 (installed version: 1.0.6)
After looking at the parts of configure script checking the library versions, it seems that it compares versions with strcmp or strncmp. Since "1.2.11" is lexicographically smaller that "1.2.6" it return a non-zero value indicating that the match failed. Besides, it just compares the first 5 characters which is also not what it is intented. So, it's a bug in configure script. Changing the script fixed the issue.
For zlib, find this line:
exit(strncmp(ZLIB_VERSION, "1.2.5", 5) < 0);
Change it to:
exit(ZLIB_VERNUM < 0x1250);
I had some issues installing R myself, specifically with the error
checking for BZ2_bzlibVersion in -lbz2... no
I had to install libbz2-dev to get that error to go away.
Unfortunately, I came across a few more issues while running ./configure and had to do a little more digging to find out how to solve it.
Discussion on issue
After reading that, I had realized I had to install a couple packages like libcurl4-openssl-dev, libpcre3, and liblzma-dev to finally finish the configuration.
The cited link suggested
At this stage you could have as well tried to install R 3.2.0RC ...
R-devel has not yet diverged much.
Personally, I think that installing an older version to resolve dependency issues reeks of laziness, but that's just my two cents.

R 3.2, GCC, and homebrew

I recently needed to install R 3.2 to get a package from Bioconductor working, but after I installed, I get the following error:
[16:16:11 20] $ r
dyld: Library not loaded: /usr/local/lib/gcc/4.9/libgfortran.3.dylib
Referenced from: /usr/local/Cellar/r/3.2.0/R.framework/Versions/3.2/Resources/lib/libR.dylib
Reason: image not found
Trace/BPT trap: 5
Sure enough, brew was set to use gcc 5, so I told brew to use the 4.9 version
brew switch gcc 4.9
which got R running, but then R would fail in the middle of a package install (specifically when I ran biocLite('DESeq2').
Since then, I have tried a number of things, including trying to install gcc 4.8 (but I can't seem to get R to use it, even via ~/.R/Makevars). Even if 4.9 is not installed, R insists on calling the path shown above.
The windows version of R seems to say 4.9 does not work with 3.2:
R-devel temporarily used a new toolchain based on 4.9.2 gcc, put together by Duncan Murdoch using build scripts written by a contractor. However, there were too many incompatibilities with existing code, and this toolchain will not be used for R 3.2.0. See notes for details on building and testing the new toolchain.
Any help would be greatly appreciated!
Edit:
I tried installing from source, as suggested by #lmw., but it fails:
[11:27:55 2] $ brew install r --build-from-source
==> Installing r from homebrew/homebrew-science
==> Installing r dependency: gcc
==> Downloading http://ftpmirror.gnu.org/gcc/gcc-5.1.0/gcc-5.1.0.tar.bz2
######################################################################## 100.0%
curl: (28) Resolving timed out after 5542 milliseconds
Trying a mirror...
==> Downloading https://ftp.gnu.org/gnu/gcc/gcc-5.1.0/gcc-5.1.0.tar.bz2
######################################################################## 100.0%
==> Patching
patching file gcc/jit/Make-lang.in
==> ../configure --build=x86_64-apple-darwin14.3.0 --prefix=/usr/local/Cellar/gcc/5.1.0 --libdir=/usr/local/Cellar/gc
==> make bootstrap
==> make install
==> Caveats
GCC has been built with multilib support. Notably, OpenMP may not work:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60670
If you need OpenMP support you may want to
brew reinstall gcc --without-multilib
==> Summary
🍺 /usr/local/Cellar/gcc/5.1.0: 1351 files, 248M, built in 32.5 minutes
==> Installing r
==> Using Homebrew-provided fortran compiler.
This may be changed by setting the FC environment variable.
==> Downloading http://cran.rstudio.com/src/base/R-3/R-3.2.0.tar.gz
######################################################################## 100.0%
==> Patching
patching file src/modules/lapack/vecLibg95c.c
==> ./configure --prefix=/usr/local/Cellar/r/3.2.0_1 --with-libintl-prefix=/usr/local/opt/gettext --enable-memory-pro
==> make
** installing vignettes
** testing if installed package can be loaded
* DONE (survival)
make[1]: *** [recommended-packages] Error 2
make: *** [stamp-recommended] Error 2
READ THIS: https://git.io/brew-troubleshooting
If reporting this issue please do so at (not Homebrew/homebrew):
https://github.com/homebrew/homebrew-science/issues
Edit 2:
Just for the fun of it, I tried installing r without the --build-from-source option, and it worked. See my solution below. (I think building from source may have fixed the issue with the gcc 5 upgrade, which got things working. I am not going to try it (things are finally working again...why screw with it?), but I wonder if I could remove the variables I set in ~/.R/Makevars (again, see solution below).
Rebuilding R from source fixes the same problem for me.
brew reinstall r --build-from-source
This was resolved by this commit, with new bottles for R. Make sure you brew update and brew upgrade r.
This is not a complete fix (it uses an older gcc version), but it get's me running again:
brew tap homebrew/homebrew-versions
brew install gcc48
brew install r
NOTE: I ran brew install r --build-from-source (reinstall did not work), which rebuilt something, but not r (it failed). It may be partially responsible for this working. Please let me know if it is! I'd like to give #lmw credit if his answer is the reason this worked.
Edit ~/.R/Makevars and add the following lines (edit paths as necessary):
CC=/usr/local/Cellar/gcc48/4.8.4/bin/gcc-4.8
CXX=/usr/local/Cellar/gcc48/4.8.4/bin/g++-4.8
CFLAGS=-std=c99
Run r.
(If you're trying to install bioconductor)
source("http://bioconductor.org/biocLite.R")
biocLite()

R cmd check not locating texi2pdf on mac after R 3.1.3 upgrade

Does anyone have a link to clear instructions on how to install and configure the necessary latex packages to build R packages on a mac?
I have some scripts for building and checking R packages on a mac server. They seemed to work fine, but after upgrading to R 3.1.3, many of the packages started failing with
Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet, :
Running 'texi2dvi' on 'networkVignette.tex' failed.
Messages:
sh: /usr/local/bin/texi2dvi: No such file or directory
Calls: <Anonymous> -> texi2pdf -> texi2dvi
Execution halted
I found a thread which seemed to suggest I need a more recent version texinfo (5.2) than what is installed by default. And apparently I've I've got the wrong version installed in the wrong location?
which texi2pdf
/sw/bin/texi2pdf
texi2pdf --version
texi2pdf (GNU Texinfo 5.1) 5234
(same version is reported when running system('texi2pdf --version') in R )
This thread gives a link to a texinfo 5.2 source collection:
http://r.789695.n4.nabble.com/R-CMD-build-looking-for-texi2dvi-in-the-wrong-place-R-devel-td4701706.html
But I'm not familiar with installing executable from a tar.gz file on a mac. The R mac help pages I found suggest installing MacTex, which I tried but that didn't seem to help.
** Update: ** additional discussion of related problems on R-SIG-mac mailing list:
https://groups.google.com/forum/#!topic/r-sig-mac/xjyuFdl5Ezk
Update:
Here is where I'm currently at:
I removed my /sw directory to uninstall fink and all of its packages (couldn't figure out how to upgrade it)
installed homebrew
brew install texinfo installs version 5.2 the package,
but generates the message This formula is keg-only, which means it was not symlinked into /usr/local and actually installs in in /usr/local/Cellar/texinfo/5.2/bin which means it is not on the path and R won't find it.
manually symlink each of the texi2pdf, texi2dvi , etc as vincent suggests (this is because R has the /usr/local/bin location as default in the tools::texi2dvi function?
edited the /etc/paths file on the system to add /usr/local/bin so that finds the brew installed 5.2 version before it finds it before the osx system supplied version 4.6 version. This may not be necessary because R has it hardcoded?
All of this gets rid of the "can't find texi* errors", and gives me a bunch of latex errors (which I don't see on unix and windows builds) so I'm still kind of stuck.
This seems very hackish, so there must be a cleaner way? But it sounds like stuff with tex and mac is very sketchy at the moment? https://tex.stackexchange.com/questions/208181/why-did-my-tex-related-gui-program-stop-working-in-mac-os-x-yosemite
This worked for me on Mavericks and on Yosemite:
ln -s /usr/bin/texi2dvi /usr/local/bin/texi2dvi
ln -s /usr/bin/texi2pdf /usr/local/bin/texi2pdf
On my Lion system both the command which texi2pdf at a Terminal/bash prompt and from a R.app GUI prompt tell me that I have that program in:
system("which texi2pdf")
#/opt/local/bin/texi2pdf
That is a location typical for MacPorts installation. I think the /usr/local/bin/ is what the binary R version "expects". I'm not really that UNIX savvy, but I think the you can modify the PATH environment variable so that R will be able to find your installation. (Whether it will be compatible I cannot say since so much detail is missing from your question.) My Tex installation is MacTex, which I got from https://www.tug.org/mactex/. I admit to having a cobbled-together system:
system("echo $PATH")
# /opt/local/bin:/opt/local/sbin:/sw/bin:/sw/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/usr/X11/bin:/usr/X11R6/bin
That gets set at the beginning of an R session because this is the first line in my .Rprofile-(invisible)file:
Sys.setenv(PATH="/opt/local/bin:/opt/local/sbin:/sw/bin:/sw/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/usr/X11/bin:/usr/X11R6/bin")
I think /sw/bin/ installations signify a fink install, which I have had very little success with. Simon Urbanek suggests not using any package installers, but then leaves the rest of us UNIX weenies very little in the way of worked examples of how to install that various external packages that underpin the many interesting and oh-so-useful R packages. So I feel your pain, but I'm not running for President.
So I suppose you could try this at your R console before again attempting one of the earlier unsuccessful installs:
Sys.setenv(PATH=paste( Sys.getenv()$PATH, # should be the character string of the $PATH
"/sw/bin/", sep=":")
)
Wish I could offer guarantees, but if it breaks the only guarantee is that you get to keep all the pieces.
I ran into a similar error message using Mavericks 10.9.5 (factory configured) and R 3.1.
It turns out that I didn't have pdfLaTex. I went to this page: http://tug.org/mactex/ and downloaded the MacTex installation package. It's big (>2GB) but after I installed it, my R package build problems went away.
Hope this might be helpful to anyone else who runs into this error message.

Resources