Unable to install R package requiring compiled C++ code (macOS Big Sur 11.4) - c++

After updating to macOS Big Sur 11.4 and installing the latest versions of R (4.1.0), RStudio (1.4.1717) and Xcode (12.5.1) (for Command Line Tools), I am unable to build and install my R package from source (which relies on complied C++ code) via devtools::build() and devtools::install().
Every time I do this in RStudio, I receive the error message:
Error: Could not find tools necessary to compile a package
Call `pkgbuild::check_build_tools(debug = TRUE)` to diagnose the problem.
When I call the above, I am prompted to select "Yes" to install the build tools. However, when I nothing happens.
I have checked to ensure Xcode CLT is installed, and sure enough, it is:
$ xcode-select -p
/Applications/Xcode.app/Contents/Developer
My package relies on both Rcpp and RcppArmadillo. I have installed these within RStudio. devtools is also installed.
I cannot even install my package directly from GitHub via devtools::install_github()
Any ideas on what could be going on here and how I can resolve the issue?
I followed the steps in this post:
clang-7: error: linker command failed with exit code 1 for macOS Big Sur
including altering the Makevars as per the above post.
If it helps, here is my old Makevars
## With R 3.1.0 or later, you can uncomment the following line to tell R to
## enable compilation with C++11 (where available)
##
## Also, OpenMP support in Armadillo prefers C++11 support. However, for wider
## availability of the package we do not yet enforce this here. It is however
## recommended for client packages to set it.
##
## And with R 3.4.0, and RcppArmadillo 0.7.960.*, we turn C++11 on as OpenMP
## support within Armadillo prefers / requires it
CXX_STD = CXX11
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
Thanks!

Related

rJava installation ld:library not found for -lpcre2-8

Trying to use rJava and have it use java version 11.
Currently it uses a previous installation I had of version 17.
When I run R CMD javareconf most of the settings look right.
Java interpreter : /Users/adam/.jenv/shims/java
Java version : 11.0.13
Java home path : /Library/Java/JavaVirtualMachines/zulu11.52.13-ca-jdk11.0.13-macosx_aarch64/zulu-11.jdk/Contents/Home
Java compiler : /Users/adam/.jenv/shims/javac
Java headers gen.: /Users/adam/.jenv/shims/javah
Java archive tool: /Users/adam/.jenv/shims/jar
...
and yet when I call rJava::.jcall("java.lang.System","S","getProperty","java.version") I still get version 17.
Consequently I've tried re-installing rJava from source. When I do this the installation recognizes Java 11 as the "default" java installation to use, but I run into a problem with my cpp compiler, as I see the error
ld: library not found for -lpcre2-8
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libjri.jnilib] Error 1
make[1]: *** [src/JRI.jar] Error 2
make: *** [jri] Error 2
ERROR: compilation failed for package ‘rJava’
when I run install.packages("rJava",type="source").
Other questions(1,2,3) have similar issues but my attempts to replicate the installation of the linker libraries, libpcre2-dev libbz2-dev zlib1g-dev as recommended to an ubuntu user did not work for me – I have not been able to find out how I might install the library as a Mac user . Furthermore, I'm not exactly sure if the "linkages" are setup appropriately in such cases.
Question
How/Where can I find and install the -lpcre2-8 package for the mac version specified below and ensure that the appropriate linkages are in place for the rJava compilation?
Details
I'm working on a Mac OS v12.0.1 (M1 chip), R v.4.1.2 using Rstudio v1.4.1717 to run R.
First, re-compiling won't have any effect. The Java version used on macOS is governed by:
the JAVA_HOME environment variable
system Java selection (see /usr/libexec/java_home)
Normally, JAVA_HOME is not set, so your macOS system setting is used. You can see your installed Java versions with /usr/libexec/java_home -V including which is selected:
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
17, x86_64: "Java SE 17" /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
1.8.0_252, x86_64: "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
If you want to change the default, you can set JAVA_HOME to the preferred value. For example:
## use Java 1.8
$ JAVA_HOME=`/usr/libexec/java_home -v 1.8` Rscript -e \
'print(rJava::J("java.lang.System")$getProperty("java.version"))'
[1] "1.8.0_252"
## use Java 17
$ JAVA_HOME=`/usr/libexec/java_home -v 17` Rscript -e \
'print(rJava::J("java.lang.System")$getProperty("java.version"))'
[1] "17"
Second, if you want to re-compile rJava, you will need all libraries used to build R. For CRAN R build those are provided in https://mac.r-project.org/bin/, but I would not recommend going there unless you want to modify rJava. You can make your life easier by not compiling JRI (embedding R in Java) support, i.e. adding --disable-jri since it's that part which requires the libraries used by R. Just the rJava package itself doesn't need it.
Finally, it's usually a lot faster to ask on the support page rJava Discussion.

linking of C++ and Python with BOOST; error = rule "Copyright" unknown in module "xml"

I am trying to execute linking of C++ and Python with BOOST.
Using the example from https://www.boost.org/doc/libs/1_63_0/libs/python/doc/html/tutorial/tutorial/hello.html#tutorial.hello.let_s_jam, and issuing bjam at ~/libs/python/example/tutorial/ which contains these files:
hello.cpp hello.py Jamfile
The read-out from the console error is:
/home/benjamin/boost/boost_1_71_0/tools/build/src/tools/types/xml.jam:12:
in load ERROR: rule "Copyright" unknown in module "xml".
Here is what I undertook to solve this problem:
I built boost from boost_1_71_0.tar.bz2 using the ./b2 file in the directory /boost/boost_1_71_0/ which is dated November 14, 2019.
My Ubuntu 18.04 system has a b2 link at /usr/bin/b2 -> bjam, which is older (March 6, 2018) and the bjam file (March 6, 2018).
No other bjam files exist on the system.
From bjam for boost 1.54, I tried:
sudo-apt install bjam
error: E: Package 'bjam' has no installation candidate.
All the programs in the user-config.jam file (e.g., c++, msvc/code, python3) are correct, which is located in my /home/benjamin/boost/boost_1_71_0/tools/build/example/.
For pity's sake and to help me (newbie), please advise.
Looking at error message it seems that error is with file /home/benjamin/boost/boost_1_71_0/tools/build/src/tools/types/xml.jam
I checked with my local installation (which is boost 1.65.1), but I am not able to locate any file with name xml.jam. But I have few other .jam file at location /usr/share/boost-build/src/tools/types/. As example
asm.jam
# Copyright Craig Rodrigues 2005. Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
type ASM : s S asm ;
So it seems that your xml.jam either invalid OR few lines should be commented (as in above file).
Try below options.
Check your xml.jam, if there are any content which are not related jam then you should comment out information.
Rename your xml.jam to xml.jam.bkp. This file may not be needed.(Not needed in my case with boost 1.65.1)
Try to install everything from Ubuntu package manager and use that. You can install all boost module by sudo apt install libboost-all-dev. I tried https://github.com/boostorg/python/tree/develop/example code with my local installed boost (1.65.1) from package manager and it work fine.

Installing OpenCV 3 in Homebrew using libstdc++

I am installing Caffe on Mac OS X 10.11 El Capitan, which somehow requires that I install OpenCV with libstdc++. To do so, I did "brew update opencv" and adding the following lines below "def install" as mentioned on the Caffe website (http://caffe.berkeleyvision.org/install_osx.html):
def install
# ADD THE FOLLOWING:
ENV.append "CXXFLAGS", "-stdlib=libstdc++"
ENV.append "CFLAGS", "-stdlib=libstdc++"
ENV.append "LDFLAGS", "-stdlib=libstdc++ -lstdc++"
# The following is necessary because libtool likes to strip LDFLAGS:
ENV["CXX"] = "/usr/bin/clang++ -stdlib=libstdc++"
...
However, when I go install it using "brew install --build-from-source -vd opencv", I get the following error:
cd /tmp/opencv-20170909-8122-1xa5qpl/opencv-3.3.0/build/modules/dnn &&
/usr/local/Cellar/cmake/3.9.2/bin/cmake -E cmake_symlink_library
../../lib/libopencv_dnn.3.3.0.dylib ../../lib/libopencv_dnn.3.3.dylib
../../lib/libopencv_dnn.dylib [ 59%] Built target opencv_dnn make: ***
[all] Error 2 /usr/local/Homebrew/Library/Homebrew/debrew.rb:11:in
`raise' BuildError: Failed executing: make
1. raise
2. ignore
3. backtrace
4. irb
5. shell Choose an action:
Anyone know how to solve this? Thank you in advance!
EDIT: Actually, I realized that my original opencv.rb file is producing the exact same problem. How do I fix/find an opencv.rb file that works?
It looks like he build you are going for in not compatible with the OS. If installing on Mac would suggest trying this method of implementation. It also uses homebrew but allows for a quick and simple implementation.

Protobuf 3.0.0-alpha-1 not compiling on windows

I'm trying to compile protobuf 3.0.0 alpha 1 on Windows using MinGW 4.9.2 & MSYS.
According to the instructions I'm supposed to:
./configure
make
make check
make install
I added --prefix=/c/path/to/mingw to configure (How to build Google's protobuf in Windows using MinGW?) but it didnt help.
It fails at make with the message:
CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/sh /home/Markus/protobuf-3.0.0-alpha-
1/missing aclocal-1.14 -I m4
/home/Markus/protobuf-3.0.0-alpha-1/missing: line 81: aclocal-1.14: command not
found
WARNING: 'aclocal-1.14' is missing on your system.
You should only need it if you modified 'acinclude.m4' or
'configure.ac' or m4 files included by 'configure.ac'.
The 'aclocal' program is part of the GNU Automake package:
<http://www.gnu.org/software/automake>
It also requires GNU Autoconf, GNU m4 and Perl in order to run:
<http://www.gnu.org/software/autoconf>
<http://www.gnu.org/software/m4/>
<http://www.perl.org/>
make: *** [aclocal.m4] Error 127
I've tried installing Automake but it doesnt come with aclocal.
Also today at work i managed to get it working on the first try with a bare MinGW & MSYS.
It looks like you need to install autoconf (which is separate from automake, though they are often used together). You may also need to install libtool.

How do I specify LDFLAGS and CPPFLAGS for ./configure?

I am using a Mac running OS X 10.8.3. I am trying to compile cgminer 3.0.0. On my first run of ./configure I got the message:
checking for LIBCURL... no
checking for LIBCURL... no
configure: error: Missing required libcurl dev >= 7.18.2
So I installed the latest version of libcurl using homebrew:
brew install curl
That seemed to do the trick. I got this message:
downloaded: /Library/Caches/Homebrew/curl-7.30.0.tar.gz
==> ./configure --prefix=/usr/local/Cellar/curl/7.30.0
==> make install
==> Caveats
This formula is keg-only: so it was not symlinked into /usr/local.
Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.
The libcurl provided by Leopard is too old for CouchDB to use.
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
LDFLAGS: -L/usr/local/opt/curl/lib
CPPFLAGS: -I/usr/local/opt/curl/include
==> Summary
/usr/local/Cellar/curl/7.30.0: 75 files, 2.0M, built in 61 seconds
Okay, so it's installed but not symlinked into /usr/local, that's fine with me. I tried this:
export LDFLAGS=-L/usr/local/opt/curl/lib
export CPPFLAGS=-I/usr/local/opt/curl/include
./configure
But I got the same message: configure: error: Missing required libcurl dev >= 7.18.2
So I tried this:
env LDFLAGS=-L/usr/local/opt/curl/lib CPPFLAGS=-I/usr/local/opt/curl/include ./configure
I'm still getting the "missing required libcurl" message. Any ideas?
After some more thorough investigation, I determined that the configure file for cgminer does not pay attention to LDFLAGS or CPPFLAGS when testing for libcurl. Instead, it checks for LIBCURL_CFLAGS and LIBCURL_LIBS. So, I tried:
export LIBCURL_CFLAGS=-I/usr/local/opt/curl/include
export LIBCURL_LIBS=-L/usr/local/opt/curl/lib
./configure
and I got:
checking for LIBCURL... yes
And the rest of the configuration went off without a hitch. SUCCESS!