Rcpp install fails on Mac 10.8 - r

Rcpp is failing to install for me. When I run the following within the R console (R 2.15.1 on Mac 10.8):
install.packages("Rcpp")
I get the following error:
/usr/bin/clang++ -I/usr/local/Cellar/r/2.15.1/R.framework/Resources/include \
-DNDEBUG -I../inst/include/ -I/usr/local/Cellar/readline/6.2.4/include \
-isystem /usr/local/include -I/opt/X11/include -fPIC -Os -w -pipe - \
march=native -Qunused-arguments -mmacosx-version-min=10.8 \
-c exceptions.cpp -o exceptions.o
exceptions.cpp:82:14: fatal error: 'bits/exception_defines.h' file not found
#include <bits/exception_defines.h>
^
1 error generated.
make: *** [exceptions.o] Error 1
ERROR: compilation failed for package ‘Rcpp’
What am I doing wrong?

Which version of Rcpp? This is fixed in SVN:
2012-07-06 Dirk Eddelbuettel <edd#debian.org>
* inst/include/Rcpp/config.h: In order to not attempt to include
exception_defines.h if on OS X (as the clang runtime may not have
predictable access to g+++ headers providing these), do not define
RCPP_HAS_DEMANGLING which is used in src/exceptions.cpp
and was discussed on the rcpp-devel list.
I tried to accomodate OS X and clang >= 3.0, but the interaction of clang and g++ is a little tricky. Try to fetch the file from SVN or just edit the section in it to yield
#ifdef __GNUC__
// from http://sourceforge.net/apps/mediawiki/predef/index.php?\
// title=Operating_Systems#MacOS
#ifndef __APPLE__
#ifndef __MACH__
#define RCPP_HAS_DEMANGLING
#endif
#endif
#endif
which turns this off for all OS X instances.

Related

build x264 failed on apple M1, No working C compiler found

Apple M1, clang
Apple clang version 13.0.0 (clang-1300.0.29.3)
Target: arm64-apple-darwin21.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
x264 version x264-snapshot-20191217-2245
configure
./configure --prefix=/tmp/ --enable-static
config.log
checking for -Werror=unknown-warning-option... yes
checking for -mdynamic-no-pic... yes
x264 configure script
Command line options: "--prefix=/tmp/" "--enable-static"
checking whether gcc works... no
Failed commandline was:
--------------------------------------------------
gcc conftest.c -Wall -I. -I$(SRCPATH) -mdynamic-no-pic -arch armv7 -Werror=unknown-warning-option -lm -arch armv7 -o conftest
ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.0.0/lib/darwin/libclang_rt.osx.a, missing required architecture armv7 in file /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.0.0/lib/darwin/libclang_rt.osx.a (5 slices)
ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libm.tbd, missing required architecture armv7 in file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libm.tbd (3 slices)
ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd, missing required architecture armv7 in file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd (3 slices)
ld: dynamic main executables must link with libSystem.dylib for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
--------------------------------------------------
Failed program was:
--------------------------------------------------
int main (void) { return 0; }
--------------------------------------------------
DIED: No working C compiler found.
x264 source snapshot tarballs have not been updated for a long time. You need to update x264 sources to a newer version: https://code.videolan.org/videolan/x264/
Apple Silicon support in x264 was added at the end of 2020.

Package building in R with Rcpp -- failure to build a package

I am very new to building packages in R, but I am trying to build a package of already written cpp code to use it in a foreach code, as I am running my code on a Windows machine and I can't pass the cpp code to the nodes.
The cpp code I am trying to wrap in an R package comes from:
https://github.com/darinchristensen/conley-se
I am following the instructions from this website to build the package:
http://web.mit.edu/insong/www/pdf/rpackage_instructions.pdf
Here is the code I am using:
setwd("C:/Users/Tim/Documents/code/")
library(Rcpp)
library(RcppArmadillo)
RcppArmadillo.package.skeleton("itirun")
Then, I try
setwd("C:/Users/Tim/Documents/code/itirun/")
compileAttributes(verbose=TRUE)
And then in terminal I go to the directory, and run the following command which gives me the following error message. I am a newbie at building packages, and I fail to understand what I am doing wrong. I also tried adding compiler flags, but wasn't successful which is probably due to my lack of understanding:
C:\Users\Tim\Documents\code> R CMD build itirun
* checking for file 'itirun/DESCRIPTION' ... OK
* preparing 'itirun':
* checking DESCRIPTION meta-information ... OK
* cleaning src
installing the package to process help pages
Warning: running command '"C:/PROGRA~1/MICROS~2/ROPEN~1/R-
34~1.2/bin/x64/Rcmd.ex
e" INSTALL -l "C:\Users\Tim\AppData\Local\Temp\RtmpA39cZK\Rinst2c0631ac5b" -
-no
-multiarch "C:/Users/Tim/AppData/Local/Temp/RtmpA39cZK/Rbuild2c02fc3722a/itirun
"' had status 1
-----------------------------------
* installing *source* package 'itirun' ...
** libs
c:/Rtools/mingw_64/bin/g++ -m64 -I"C:/PROGRA~1/MICROS~2/ROPEN~1/R-34~1.2/include
" -DNDEBUG -I"C:/Users/Tim/Documents/R/win-library/3.4/Rcpp/include" -I"C:/Use
rs/Tim/Documents/R/win-library/3.4/RcppArmadillo/include" -I"C:/swarm/workspa
ce/External-R-3.4.2/vendor/extsoft/include" -fopenmp -O2 -Wall -mtune=core2
-c RcppExports.cpp -o RcppExports.o
In file included from C:/Users/Tim/Documents/R/win-library/3.4/RcppArmadillo/in
clude/armadillo:53:0,
from C:/Users/Tim/Documents/R/win-library/3.4/RcppArmadillo/in
clude/RcppArmadilloForward.h:46,
from C:/Users/Tim/Documents/R/win-library/3.4/RcppArmadillo/in
clude/RcppArmadillo.h:31,
from RcppExports.cpp:4:
C:/Users/Tim/Documents/R/win-library/3.4/RcppArmadillo/include/armadillo_bits/c
ompiler_setup.hpp:487:118: note: #pragma message: WARNING: support for OpenMP re
quires C++11/C++14; add -std=c++11 or -std=c++14 to compiler flags
#pragma message ("WARNING: support for OpenMP requires C++11/C++14; add -std=
c++11 or -std=c++14 to compiler flags")
^
c:/Rtools/mingw_64/bin/g++ -m64 -I"C:/PROGRA~1/MICROS~2/ROPEN~1/R-34~1.2/include
" -DNDEBUG -I"C:/Users/Tim/Documents/R/win-library/3.4/Rcpp/include" -I"C:/Use
rs/Tim/Documents/R/win-library/3.4/RcppArmadillo/include" -I"C:/swarm/workspa
ce/External-R-3.4.2/vendor/extsoft/include" -fopenmp -O2 -Wall -mtune=core2
-c cpp-functions.cpp -o cpp-functions.o
In file included from C:/Users/Tim/Documents/R/win-library/3.4/RcppArmadillo/in
clude/armadillo:53:0,
from C:/Users/Tim/Documents/R/win-library/3.4/RcppArmadillo/in
clude/RcppArmadilloForward.h:46,
from C:/Users/Tim/Documents/R/win-library/3.4/RcppArmadillo/in
clude/RcppArmadillo.h:31,
from cpp-functions.cpp:4:
C:/Users/Tim/Documents/R/win-library/3.4/RcppArmadillo/include/armadillo_bits/c
ompiler_setup.hpp:487:118: note: #pragma message: WARNING: support for OpenMP re
quires C++11/C++14; add -std=c++11 or -std=c++14 to compiler flags
#pragma message ("WARNING: support for OpenMP requires C++11/C++14; add -std=
c++11 or -std=c++14 to compiler flags")
^
In file included from C:/Users/Tim/Documents/R/win-library/3.4/RcppArmadillo/in
clude/RcppArmadillo.h:38:0,
from cpp-functions.cpp:4:
C:/Users/Tim/Documents/R/win-library/3.4/RcppArmadillo/include/RcppArmadilloAs.
h: In instantiation of 'Rcpp::traits::Exporter<arma::Cube<eT> >::cube_t Rcpp::tr
aits::Exporter<arma::Cube<eT> >::get() [with T = long long int; Rcpp::traits::Ex
porter<arma::Cube<eT> >::cube_t = arma::Cube<long long int>]':
C:/Users/Tim/Documents/R/win-library/3.4/RcppArmadillo/include/RcppArmadilloAs.
h:549:48: required from here
C:/Users/Tim/Documents/R/win-library/3.4/RcppArmadillo/include/RcppArmadilloAs.
h:514:49: error: invalid cast from type 'Rcpp::Vector<19>::iterator {aka Rcpp::i
nternal::Proxy_Iterator<Rcpp::internal::generic_proxy<19> >}' to type 'long long
int*'
dims[0], dims[1], dims[2], false);
^
make: *** [cpp-functions.o] Error 1
Warning: running command 'make -f "Makevars.win" -f "C:/PROGRA~1/MICROS~2/ROPEN~
1/R-34~1.2/etc/x64/Makeconf" -f "C:/PROGRA~1/MICROS~2/ROPEN~1/R-34~1.2/share/mak
e/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHL
IB="itirun.dll" WIN=64 TCLBIN=64 OBJECTS="RcppExports.o cpp-functions.o rcpparma
_hello_world.o"' had status 2
ERROR: compilation failed for package 'itirun'
* removing 'C:/Users/Tim/AppData/Local/Temp/RtmpA39cZK/Rinst2c0631ac5b/itirun'
-----------------------------------
ERROR: package installation failed

Cannot install R with cairo

I' am installing R from source:
cd R-3.2.2
./configure --prefix=$( pwd ) --with-cairo=yes --with-readline=no --with-libpng=yes --with-x=no
I already have cairo (v1.14.8) and pango (v1.40.6) installed from source (neither had any errors while installing). But R does not configure with cairo:
R is now configured for x86_64-pc-linux-gnu
Source directory: .
Installation directory: /athena/elementolab/scratch/chm2059/from_dat02/chm2059/lib/R-3.2.2
C compiler: gcc -std=gnu99 -I/athena/elementolab/scratch/chm2059/from_dat02/chm2059/lib/bzip2-1.0.6/include/packages/include
Fortran 77 compiler: gfortran -g -O2
C++ compiler: g++ -g -O2
C++ 11 compiler: g++ -std=c++11 -g -O2
Fortran 90/95 compiler: gfortran -g -O2
Obj-C compiler:
Interfaces supported:
External libraries: zlib, PCRE, curl
Additional capabilities: NLS
Options enabled: shared BLAS, R profiling
Capabilities skipped: PNG, JPEG, TIFF, cairo, ICU
Options not enabled: memory profiling
Recommended packages: yes
configure: WARNING: you cannot build info or HTML versions of the R manuals
configure: WARNING: you cannot build PDF versions of the R manuals
configure: WARNING: you cannot build PDF versions of vignettes and help pages
I see these lines while it configures:
checking for X... disabled
using X11 ... no
checking whether pkg-config knows about cairo and pango... yes
checking whether cairo including pango is >= 1.2 and works... no
Any thoughts?
I had the same problem in Why do Greek letters fail to render in R's (v4) PDF output? - this is how I fixed it for R 4.0.3:
Open the configure script, and find this:
$as_echo_n "checking whether cairo including pango is >= 1.2 and works... " >&6; }
if ${r_cv_cairo_works+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <pango/pango.h>
#include <pango/pangocairo.h>
#include <cairo-xlib.h>
#if CAIRO_VERSION < 10200
#error cairo version >= 1.2 required
#endif
int main(void) {
cairo_t *CC = NULL; // silence picky compilers
cairo_arc(CC, 0.0, 0.0, 1.0, 0.0, 6.28);
pango_cairo_create_layout(CC);
pango_font_description_new();
return 0;
}
_ACEOF
Copy this core code part into some test.c file:
#include <pango/pango.h>
#include <pango/pangocairo.h>
#include <cairo-xlib.h>
#if CAIRO_VERSION < 10200
#error cairo version >= 1.2 required
#endif
int main(void) {
cairo_t *CC = NULL; // silence picky compilers
cairo_arc(CC, 0.0, 0.0, 1.0, 0.0, 6.28);
pango_cairo_create_layout(CC);
pango_font_description_new();
return 0;
}
Then run cc test.c $(pkg-config --cflags --libs pangocairo). This may give you some more information on why the configure test is failing. Also use
cc test.c $(pkg-config --cflags --libs pangocairo) --verbose
and
cc test.c $(pkg-config --cflags --libs pangocairo) -Wl,--verbose
to obtain even more information.
In my case, I finally got this after installing a few missing packages:
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: cannot find -lharfbuzz
collect2: error: ld returned 1 exit status
The reason was a broken link in /usr/lib64:
Once that was repaired, everything worked: lacking root right, I used
mkdir ~/lib
cp /usr/lib64/libharfbuzz.so.0 ~/lib/libharfbuzz.so
export LIBRARY_PATH=~/lib
Then, cc test.c $(pkg-config --cflags --libs pangocairo) finished, and configuring with pango and cairo worked as well.

Issue compiling Rcpp programs with user-defined header files on Windows

1. Issue
I was trying to compile an Rcpp program with a user-defined .hpp header file following an example in http://dirk.eddelbuettel.com/code/rcpp/Rcpp-attributes.pdf, p9, section 2.10.2. It compiles nicely in RStudio on my Mac and works well.
However, when I run exactly the same program on my Windows 64-bits laptop (Win 7), I get the following error message:
g++ -m64 -I"G:/R-32~1.3/include" -DNDEBUG -I"G:/R-3.2.3/library/Rcpp/include" -I"F:/_tst/rcpp" -I"d:/RCompile/r-compiling/local/local323/include" -O2 -Wall -mtune=core2 -c tst4.cpp -o tst4.o
G:\Rtools\gcc-4.6.3\bin\nm.exe: 'F:_tstrcpputilities.o': No such file
g++ -m64 -shared -s -static-libgcc -o sourceCpp_1.dll tmp.def F:_tstrcpputilities.o tst4.o -Ld:/RCompile/r-compiling/local/local323/lib/x64 -Ld:/RCompile/r-compiling/local/local323/lib -LG:/R-32~1.3/bin/x64 -lR
g++.exe: error: F:_tstrcpputilities.o: No such file or directory
Error in sourceCpp("tst4.cpp") : Error occurred building shared library.
It seems like the slashes in the file paths are lost (I assume instead of 'F:_tstrcpputilities.o', it should be 'F:\_tst\rcpp\utilities.o'?), but I have no idea how to fix this...
2. Tentative solution but unsuccessful
I tried adding my Rtools and Rtools/gcc-x.x.x/bin directory to PATH by using devtool as follows:
add_path("G:\\Rtools");
add_path("G:\\Rtools\\bin");
add_path("G:\\Rtools\\gcc-4.6.3\\bin");
Unfortunately it did not help. The same error remains.
So...
Well, I'm stuck here... Any help would be appreciated.
=========================================================================
S1. Supplementary info
Some information about my laptop/R/Rtools:
OS: Win 7 64-bits
R version: 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"
Rtools version: Rtools3.3
The test cpp code (filename: tst4.cpp) I used was:
#include <Rcpp.h>
#include "utilities.hpp"
using namespace Rcpp;
// [[Rcpp::export]]
double timesTwenty(double x) {
return timesTwo(x) * 10;
}
All .cpp and .hpp files are in the same folder.

Rcpp compilation on windows fails (64bit)

I am trying to set up Rcpp on my Windows machine (have not had issues on my unix box).
I have installed R in C:/opt/R/current (a Google search suggested that spaces in installation paths could give trouble), and I have installed Rtools.
I have the simple cpp file:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
int timesTwo(int x) {
return x * 2;
}
and an R file:
library(Rcpp)
sourceCpp("cppfile.cpp")
I get the following error:
C:/opt/R/current/etc/x64/Makeconf:196: warning: overriding recipe for target `.m.o' C:/opt/R/current/etc/x64/Makeconf:189: warning: ignoring old recipe for target `.m.o' C:\MINGW3~1\bin\make.exe: Interrupt/Exception caught (code = 0xc0000005, addr = 0x0x750343f9) Warning message: running command 'make -f "C:/opt/R/current/etc/x64/Makeconf" -f "C:/opt/R/current/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="sourceCpp_67515.dll" WIN=64 TCLBIN=64 OBJECTS="cppfile.o"' had status 255
Error in sourceCpp("cppfile.cpp") :
Error 1 occurred building shared library.
Any help would be appreciated.
PS: Install e.g. dplyr from github via devtools works fine (and does quite a lot of compiling Rcpp stuff).
UPDATE: I added the Rtools bin dir to PATH, and now I get another error which seems to relate to 32/64bit:
g++ -m64 -I"C:/opt/R/current/include" -DNDEBUG -I"C:/opt/R/current/library/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall -mtune=core2 -c cppfile.cpp -o cppfile.o cppfile.cpp:1:0: sorry, unimplemented: 64-bit mode not compiled in make: *** [cppfile.o] Error 1 Warning message: running command 'make -f "C:/opt/R/current/etc/x64/Makeconf" -f "C:/opt/R/current/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="sourceCpp_41862.dll" WIN=64 TCLBIN=64 OBJECTS="cppfile.o"' had status 2
Error in sourceCpp("cppfile.cpp") :
Error 1 occurred building shared library.
Turned out that I needed to add both the RTools/bin and the Rtools/gcc-x.y.z/bin to PATH. Now things work smoothly.

Resources