igraph 0.7.1 failing to install on R 3.1.0 - r

I am trying to install igraph 0.7.1 on a macbook pro with mavericks. I have installed R 3.1.0 using macports and keep getting the following warnings / errors when installing igraph using install.packages("igraph"):
/usr/bin/clang -I/opt/local/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/opt/local/include -DUSING_R -I. -Ics -Iglpk -Iglpk/amd -Iglpk/colamd -Iplfit -pipe -Os -flax-vector-conversions -arch x86_64 -I/opt/local/include/libxml2 -pipe -Os -flax-vector-conversions -arch x86_64 -I/opt/local/include/libxml2 -DNDEBUG -DPACKAGE_VERSION=\"#VERSION#\" -DINTERNAL_ARPACK -DIGRAPH_THREAD_LOCAL=/**/ -fPIC -pipe -Os -flax-vector-conversions -arch x86_64 -c colamd.c -o colamd.o
colamd.c:1979:27: warning: implicitly declaring library function 'sqrt' with type 'double (double)'
dense_row_count = DENSE_DEGREE (knobs [COLAMD_DENSE_ROW], n_col) ;
^
colamd.c:792:33: note: expanded from macro 'DENSE_DEGREE'
((Int) MAX (16.0, (alpha) * sqrt ((double) (n))))
^
colamd.c:794:27: note: expanded from macro 'MAX'
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
^
colamd.c:1979:27: note: please include the header <math.h> or explicitly provide a declaration for 'sqrt'
colamd.c:792:33: note: expanded from macro 'DENSE_DEGREE'
((Int) MAX (16.0, (alpha) * sqrt ((double) (n))))
^
colamd.c:794:27: note: expanded from macro 'MAX'
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
^
1 warning generated.
The install then completes with the following error:
Error : .onLoad failed in loadNamespace() for 'igraph', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/opt/local/Library/Frameworks/R.framework/Versions/3.1/Resources/library/igraph/libs/igraph.so':
dlopen(/opt/local/Library/Frameworks/R.framework/Versions/3.1/Resources/library/igraph/libs/igraph.so, 10): Symbol not found: _colamd_printf
Referenced from: /opt/local/Library/Frameworks/R.framework/Versions/3.1/Resources/library/igraph/libs/igraph.so
Expected in: flat namespace
in /opt/local/Library/Frameworks/R.framework/Versions/3.1/Resources/library/igraph/libs/igraph.so
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/opt/local/Library/Frameworks/R.framework/Versions/3.1/Resources/library/igraph’
I have Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn) installed on my machine. I would be very grateful for some help.
Thanks in advance.

Related

R dyn.load gives "undefined symbol" error

I am writing a shared library that itself uses the uthash library in C under Ubuntu. I am going to use this shared library in R. For this purpose I have created a package.c file where the main code is stored. In order to use CALLOC function (a part of the uthash) I have included uthash.h in the beginning of package.c. In the body of package.c the CALLOC function is called.
I can build package.c without any problem by running:
R CMD SHLIB package.c
This is the output of the above command in the console:
gcc -I"/usr/local/lib/R/include" -DNDEBUG -I/usr/local/include -fpic -g -O2 -c package.c -o package.o
gcc -shared -L/usr/local/lib/R/lib -L/usr/local/lib -o package.so package.o -L/usr/local/lib/R/lib -lR
It produces two files "package.o" and "package.so". I load package.so in R using dyn:
dyn.load("package.so")
But it gives the following error message:
Error in dyn.load("package.so") :
unable to load shared object '/home/me/package/package.so':
/home/me/package/package.so: undefined symbol: memoryMap
I searched for a solution and found this. According to what is written there, here is the the output of "ldd package.so" and "nm -g package.so" commands:
"ldd package.so" output:
$ ldd package.so
linux-vdso.so.1 (0x00007ffd283da000)
libR.so => not found
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd3643b4000)
/lib64/ld-linux-x86-64.so.2 (0x00007fd3649a8000)
"nm -g package.so" outout:
$ nm -g package.so
0000000000202088 B __bss_start
U calloc##GLIBC_2.2.5
w __cxa_finalize##GLIBC_2.2.5
0000000000202088 D _edata
0000000000202090 B _end
00000000000016d8 T _fini
U free##GLIBC_2.2.5
0000000000001260 T getSteadyStateDistribution_R
w __gmon_start__
00000000000008b0 T _init
U INTEGER
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
U malloc##GLIBC_2.2.5
U memcpy##GLIBC_2.14
U memoryMap
U __printf_chk##GLIBC_2.3.4
U REAL
U Rf_error
U Rf_isNull
U Rf_length
0000000000000d70 T simulate
0000000000000e50 T simulate_R
U __stack_chk_fail##GLIBC_2.4
0000000000000aa0 T stateTransition
U unif_rand
I have also read this post but still could not find a solution for my problem.
Edit:
Here is an example to reproduce the error:
#include <R.h>
#include <Rinternals.h>
#include "uthash.h"
typedef struct
{
// a pointer to the allocated memory
void * ptr;
// used by the hash table
UT_hash_handle hh;
} AllocatedMemory;
// map that stores all allocated memory pointers
// to free them on interrupt
extern AllocatedMemory * memoryMap;
static inline void* CALLOC(size_t n, size_t sz)
{
void * ptr = calloc(n, sz);
if (ptr == NULL)
error("Out of memory!");
AllocatedMemory * m = calloc(1, sizeof(AllocatedMemory));
m->ptr = ptr;
HASH_ADD_PTR(memoryMap, ptr, m);
return ptr;
}
SEXP example_R(SEXP vec_R) {
unsigned int n = length(vec_R);
unsigned int * v = CALLOC(n, sizeof(unsigned int));
}
If the above code is stored in "example.c", compile it using:
R CMD SHLIB example.c
It will produce the files example.o and example.so. Then load the so file in R:
dyn.load('example.so')
Here is the minimal change to make your example compile and load i.e. link dynamically:
$ diff -u question.orig.c question.c
--- question.orig.c 2022-12-22 09:41:46.483509755 -0600
+++ question.c 2022-12-22 09:44:45.217420621 -0600
## -12,7 +12,8 ##
// map that stores all allocated memory pointers
// to free them on interrupt
-extern AllocatedMemory * memoryMap;
+AllocatedMemory memoryMapInstance;
+AllocatedMemory *memoryMap = &memoryMapInstance;
static inline void* CALLOC(size_t n, size_t sz)
$
Instead of the reference to an extern instance you fail to supply, but one instance (cheaply) on the stack and define the pointer you need as its address. In a real program you would allocate this on the heap.
Another remaining error is that your example_R is wrong as you claim to take and return a SEXP. But we leave this for another time.
Now with a simple wrapper questions.sh
#!/bin/bash
R CMD SHLIB question.c
R -e 'dyn.load("question.so")'
we get another warning because the return from CALLOC is unused -- but no longer an error on load.
$ ./question.sh
ccache gcc -I"/usr/share/R/include" -DNDEBUG -fpic -g -O3 -Wall -pipe -pedantic -Wno-ignored-attributes -std=gnu99 -c question.c -o question.o
question.c: In function ‘example_R’:
question.c:34:20: warning: unused variable ‘v’ [-Wunused-variable]
34 | unsigned int * v = CALLOC(n, sizeof(unsigned int));
| ^
question.c:35:1: warning: control reaches end of non-void function [-Wreturn-type]
35 | }
| ^
ccache gcc -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -o question.so question.o -L/usr/lib/R/lib -lR
R version 4.2.2 Patched (2022-11-10 r83330) -- "Innocent and Trusting"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> dyn.load("question.so")
>
>
$
No error.
(You can ignore the compiler settings, and use of ccache I have locally. The warning is real.)

How to use a user-defined data C structure into an R package

This minimal example compiles when I "source" the file:
/*
read_header.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <RcppCommon.h>
typedef struct {
int my_data;
} MY_HEADER_INFO;
namespace Rcpp {
template <> SEXP wrap(const MY_HEADER_INFO& x);
}
#include <Rcpp.h>
namespace Rcpp {
template <>
SEXP wrap(const MY_HEADER_INFO& x) {
std::vector<std::string> names;
std::vector<SEXP> elements(1);
// do something with the elements and names
names.push_back("my_data");
elements[0] = Rcpp::wrap( x.my_data );
};
}
//' #export
// [[Rcpp::export]]
MY_HEADER_INFO read_header() {
MY_HEADER_INFO *header;
header = (MY_HEADER_INFO*)malloc(sizeof(MY_HEADER_INFO));
memset(header, 0, sizeof(MY_HEADER_INFO));
return *header;
}
When I try to build it in RStudio into a package (CMD + SHIFT + B), I get the following, long, error message, that clearly lists the problem is my user-defined return structure, MY_HEADER_INFO:
DESCRIPTION
Package: myPackage
Type: Package
Title: What the Package Does (Title Case)
Version: 0.1.0
Depends: R (>= 4.0.0)
License: GPL-3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.0
Imports:
Rcpp
Suggests:
knitr,
rmarkdown,
testthat
VignetteBuilder: knitr
LinkingTo:
Rcpp
NAMESPACE
# Generated by roxygen2: do not edit by hand
export(read_header)
I receive the following error:
==> Rcpp::compileAttributes()
* Updated src/RcppExports.cpp
* Updated R/RcppExports.R
==> devtools::document(roclets = c('rd', 'collate', 'namespace'))
Updating myPackage documentation
Loading myPackage
Re-compiling myPackage
─ installing *source* package ‘myPackage’ ...
** using staged installation
** libs
clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include' -I/usr/local/include -fPIC -Wall -g -O2 -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always -c RcppExports.cpp -o RcppExports.o
RcppExports.cpp:9:1: error: unknown type name 'MY_HEADER_INFO'
MY_HEADER_INFO read_header();
^
1 error generated.
make: *** [RcppExports.o] Error 1
ERROR: compilation failed for package ‘myPackage’
─ removing ‘/private/var/folders/gl/jvj9b0xn34lgq6_h9370p8q80000gn/T/RtmpLKsw0o/devtools_install_1f333d54be59/myPackage’
Error: System command 'R' failed, exit status: 1, stdout + stderr:
E> * installing *source* package ‘myPackage’ ...
E> ** using staged installation
E> ** libs
E> clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include' -I/usr/local/include -fPIC -Wall -g -O2 -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always -c RcppExports.cpp -o RcppExports.o
E> RcppExports.cpp:9:1: error: unknown type name 'MY_HEADER_INFO'
E> MY_HEADER_INFO read_header();
E> ^
E> 1 error generated.
E> make: *** [RcppExports.o] Error 1
E> ERROR: compilation failed for package ‘myPackage’
E> * removing ‘/private/var/folders/gl/jvj9b0xn34lgq6_h9370p8q80000gn/T/RtmpLKsw0o/devtools_install_1f333d54be59/myPackage’
Stack trace:
1. base:::suppressPackageStartupMessages({ ...
2. base:::withCallingHandlers(expr, packageStartupMessage = function(c) tryInv ...
3. devtools::document(roclets = c("rd", "collate", "namespace"))
4. withr::with_envvar(r_env_vars(), roxygen2::roxygenise(pkg$path, ...
5. base:::force(code)
6. roxygen2::roxygenise(pkg$path, roclets, load_code = load_code)
7. roxygen2:::load_code(base_path)
8. pkgload::load_all(path, helpers = FALSE, attach_testthat = FALSE)
9. pkgbuild::compile_dll(path, quiet = quiet)
10. withr::with_makevars(compiler_flags(TRUE), assignment = "+=", ...
11. withr:::with_envvar(c(R_MAKEVARS_USER = makevars_file), { ...
12. base:::force(code)
13. base:::force(code)
14. pkgbuild:::install_min(path, dest = install_dir, components = "libs", ...
15. pkgbuild:::rcmd_build_tools("INSTALL", c(path, paste("--library=", ...
16. pkgbuild:::with_build_tools(callr::rcmd_safe(..., env = env, ...
17. callr::rcmd_safe(..., env = env, spinner = FALSE, show = FALSE, ...
18. callr:::run_r(options)
19. base:::with(options, with_envvar(env, do.call(processx::run, ...
20. base:::with.default(options, with_envvar(env, do.call(processx::run, ...
21. base:::eval(substitute(expr), data, enclos = parent.frame())
22. base:::eval(substitute(expr), data, enclos = parent.frame())
23. callr:::with_envvar(env, do.call(processx::run, c(list(bin, args = real_cmd ...
24. base:::force(code)
25. base:::do.call(processx::run, c(list(bin, args = real_cmdargs, ...
26. (function (command = NULL, args = character(), error_on_status = TRUE, ...
27. throw(new_process_error(res, call = sys.call(), echo = echo, ...
x System command 'R' failed, exit status: 1, stdout + stderr:
E> * installing *source* package ‘myPackage’ ...
E> ** using staged installation
E> ** libs
E> clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include' -I/usr/local/include -fPIC -Wall -g -O2 -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always -c RcppExports.cpp -o RcppExports.o
E> RcppExports.cpp:9:1: error: unknown type name 'MY_HEADER_INFO'
E> MY_HEADER_INFO read_header();
E> ^
E> 1 error generated.
E> make: *** [RcppExports.o] Error 1
E> ERROR: compilation failed for package ‘myPackage’
E> * removing ‘/private/var/folders/gl/jvj9b0xn34lgq6_h9370p8q80000gn/T/RtmpLKsw0o/devtools_install_1f333d54be59/myPackage’
Execution halted
Exited with status 1.
The following is written to Rcpp_exports:
// Generated by using Rcpp::compileAttributes() -> do not edit by hand
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
#include <Rcpp.h>
using namespace Rcpp;
// read_header
MY_HEADER_INFO read_header();
RcppExport SEXP _myPackage_read_header() {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
rcpp_result_gen = Rcpp::wrap(read_header());
return rcpp_result_gen;
END_RCPP
}
static const R_CallMethodDef CallEntries[] = {
{"_myPackage_read_header", (DL_FUNC) &_myPackage_read_header, 0},
{NULL, NULL, 0}
};
RcppExport void R_init_myPackage(DllInfo *dll) {
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
R_useDynamicSymbols(dll, FALSE);
}
If I try to modify this file, however, it all gets written over when I call CMD+SHIFT+B.
Other C programs I've written for this same package that return standard data types (e.g., "std::vector") compile without a problem, both when I "source" the code in the Console and when I build them into a package.
I have read through the Rcpp documentation and related vignettes (and even bought Dirk's book!), but I cannot find how to tell the package builder where the definition of MY_HEADER_INFO is located. How do I tell the package compiler where the definition of this file is located?
Thanks!
That look like another instance of a not-entirely-uncommon problem for which we do have a wonderfully simple answer that is somewho less known than it should be.
In short, for a package <pkg> (where <pkg> is an alias for your package name, with lower or undercase as you please. and obviously no < or >) please such struct (or in the C++ case class) or typedef or ... definitions into a file inst/include/<pkg>_types.h (replacing <pkg> with your package name).
If such a file exists, it is automagically included by RcppExports.cpp and you are good to go.
Details are in the Rcpp Attributes vignette, and a few related forms are allowed as well:
src/<pkg>_types.h
src/<pkg>_types.hpp
inst/include/<pkg>_types.h
inst/include/<pkg>_types.hpp
inst/include/<pkg>.h
but inst/include/<pkg>_types.h may be the most commonly used one. One example of using it via src/ is src/RSQLite_types.h. On the other hand, an example of using it in inst/include/ is inst/include/RcppQuantuccia_types.h and another, much larger one in inst/include/RcppGSL_types.h.

How to fix undefined references for inline functions in Rcpp

I have been continuously chugging away at building an R package to use in house. It uses Rcpp and a bunch of functions defined in C++. I'm getting and error saying there is an undefined reference to two functions. Both of which are inline functions
I've tried commenting out the functions in the RcppExports, but the code is regenerated every run. I'm not sure what esle to do.
'''R package Build
==> Rcpp::compileAttributes()
* Updated src/RcppExports.cpp
* Updated R/RcppExports.R
==> Rcmd.exe INSTALL --no-multiarch --with-keep.source PHit
* installing to library 'C:/Users/kyle.m.joshi.NAE/Documents/R/win-library/3.6'
* installing *source* package 'PHit' ...
** using staged installation
** libs
c:/Rtools/mingw_64/bin/g++ -I"C:/PROGRA~1/R/R-36~1.0/include" -DNDEBUG -I"C:/Users/kyle.m.joshi.NAE/Documents/R/win-library/3.6/Rcpp/include" -O2 -Wall -mtune=generic -c RcppExports.cpp -o RcppExports.o
make: Warning: File 'RcppExports.o' has modification time 135 s in the future
RcppExports.cpp:317:15: warning: inline function 'double mils2meters(double, double)' used but never defined
inline double mils2meters(double mils, double range);
^
RcppExports.cpp:353:15: warning: inline function 'double sqrtsumsq(double, double)' used but never defined
inline double sqrtsumsq(double a, double b);
^
c:/Rtools/mingw_64/bin/g++ -shared -s -static-libgcc -o PHit.dll tmp.def Phit.o RcppExports.o hcubature.o pcubature.o -LC:/PROGRA~1/R/R-36~1.0/bin/x64 -lR
RcppExports.o:RcppExports.cpp:(.text+0x2818): undefined reference to `mils2meters(double, double)'
RcppExports.o:RcppExports.cpp:(.text+0x35f8): undefined reference to `sqrtsumsq(double, double)'
collect2.exe: error: ld returned 1 exit status
make: warning: Clock skew detected. Your build may be incomplete.
no DLL was created
ERROR: compilation failed for package 'PHit'
* removing 'C:/Users/kyle.m.joshi.NAE/Documents/R/win-library/3.6/PHit'
* restoring previous 'C:/Users/kyle.m.joshi.NAE/Documents/R/win-library/3.6/PHit'
Exited with status 1.
'''
'''RcppExort.cpp example function
inline double mils2meters(double mils, double range);
RcppExport SEXP _PHit_mils2meters(SEXP milsSEXP, SEXP rangeSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< double >::type mils(milsSEXP);
Rcpp::traits::input_parameter< double >::type range(rangeSEXP);
rcpp_result_gen = Rcpp::wrap(mils2meters(mils, range));
return rcpp_result_gen;
END_RCPP
}
'''

Error when installing TDA package on R: recipe for target 'diag.o' failed

Using Ubuntu 16.04 and R 3.4.1. I get an error message when installing R package TDA. It appears to be something with making CGAL, diag.cpp, and/or diag.o (full error printout at end).
I looked closely at this:
Error when installing TDA package on R
but I have libgmp3-dev and libmpfr-dev installed (I tried removing them and then I did get that error message). I also tried removing and manually installing the Imports and LinkingTo packages for TDA (https://cran.r-project.org/web/packages/TDA/index.html), but no luck. Also tried
running R with sudo and install.packages
downloading the binaries and installing with sudo R CMD INSTALL TDA
installing CGAL
Any help appreciated.
install.packages("TDA")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.revolutionanalytics.com/src/contrib/TDA_1.5.1.tar.gz'
Content type 'application/octet-stream' length 2008762 bytes (1.9 MB)
==================================================
downloaded 1.9 MB
* installing *source* package ‘TDA’ ...
** package ‘TDA’ successfully unpacked and MD5 sums checked
** libs
g++ -std=gnu++11 -I/usr/share/R/include -I. -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppEigen/include" -I"/usr/local/lib/R/site-library/BH/include" -DBOOST_DISABLE_THREADS -DCGAL_EIGEN3_ENABLED -DCGAL_HEADER_ONLY -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c RcppExports.cpp -o RcppExports.o
g++ -std=gnu++11 -I/usr/share/R/include -I. -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppEigen/include" -I"/usr/local/lib/R/site-library/BH/include" -DBOOST_DISABLE_THREADS -DCGAL_EIGEN3_ENABLED -DCGAL_HEADER_ONLY -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c diag.cpp -o diag.o
In file included from ./CGAL/Triangulation_ds_cell_base_3.h:27:0,
from ./CGAL/Triangulation_data_structure_3.h:47,
from ./CGAL/Triangulation_3.h:43,
from ./CGAL/Delaunay_triangulation_3.h:37,
from ./tdautils/cgalUtils.h:5,
from diag.cpp:25:
./CGAL/Triangulation_ds_cell_base_3.h: In instantiation of ‘void CGAL::Triangulation_ds_cell_base_3<TDS>::set_neighbor(int, CGAL::Triangulation_ds_cell_base_3<TDS>::Cell_handle) [with TDS = CGAL::Triangulation_data_structure_3<CGAL::Alpha_shape_vertex_base_3<CGAL::Epick>, CGAL::Alpha_shape_cell_base_3<CGAL::Epick> >; CGAL::Triangulation_ds_cell_base_3<TDS>::Cell_handle = CGAL::internal::CC_iterator<CGAL::Compact_container<CGAL::Alpha_shape_cell_base_3<CGAL::Epick, CGAL::Triangulation_cell_base_3<CGAL::Epick, CGAL::Triangulation_ds_cell_base_3<CGAL::Triangulation_data_structure_3<CGAL::Alpha_shape_vertex_base_3<CGAL::Epick>, CGAL::Alpha_shape_cell_base_3<CGAL::Epick> > > >, CGAL::Boolean_tag<false>, CGAL::Boolean_tag<false> >, CGAL::Default, CGAL::Default, CGAL::Default>, false>]’:
./CGAL/Triangulation_data_structure_3.h:2782:7: required from ‘CGAL::Triangulation_data_structure_3<Vb, Cb, Concurrency_tag_>::Vertex_handle CGAL::Triangulation_data_structure_3<Vb, Cb, Concurrency_tag_>::insert_increase_dimension(CGAL::Triangulation_data_structure_3<Vb, Cb, Concurrency_tag_>::Vertex_handle) [with Vb = CGAL::Alpha_shape_vertex_base_3<CGAL::Epick>; Cb = CGAL::Alpha_shape_cell_base_3<CGAL::Epick>; Concurrency_tag_ = CGAL::Sequential_tag; CGAL::Triangulation_data_structure_3<Vb, Cb, Concurrency_tag_>::Vertex_handle = CGAL::internal::CC_iterator<CGAL::Compact_container<CGAL::Alpha_shape_vertex_base_3<CGAL::Epick, CGAL::Triangulation_vertex_base_3<CGAL::Epick, CGAL::Triangulation_ds_vertex_base_3<CGAL::Triangulation_data_structure_3<CGAL::Alpha_shape_vertex_base_3<CGAL::Epick>, CGAL::Alpha_shape_cell_base_3<CGAL::Epick> > > >, CGAL::Boolean_tag<false>, CGAL::Boolean_tag<false> >, CGAL::Default, CGAL::Default, CGAL::Default>, false>]’
./CGAL/Triangulation_3.h:623:16: required from ‘void CGAL::Triangulation_3<GT, Tds, Lock_data_structure>::init_tds() [with GT = CGAL::Epick; Tds_ = CGAL::Triangulation_data_structure_3<CGAL::Alpha_shape_vertex_base_3<CGAL::Epick>, CGAL::Alpha_shape_cell_base_3<CGAL::Epick> >; Lock_data_structure_ = CGAL::Default]’
./CGAL/Triangulation_3.h:655:15: required from ‘CGAL::Triangulation_3<GT, Tds, Lock_data_structure>::Triangulation_3(const GT&, CGAL::Triangulation_3<GT, Tds, Lock_data_structure>::Lock_data_structure*) [with GT = CGAL::Epick; Tds_ = CGAL::Triangulation_data_structure_3<CGAL::Alpha_shape_vertex_base_3<CGAL::Epick>, CGAL::Alpha_shape_cell_base_3<CGAL::Epick> >; Lock_data_structure_ = CGAL::Default; CGAL::Triangulation_3<GT, Tds, Lock_data_structure>::Lock_data_structure = void]’
./CGAL/Delaunay_triangulation_3.h:229:26: required from ‘CGAL::Delaunay_triangulation_3<Gt, Tds_, CGAL::Default, Lock_data_structure_>::Delaunay_triangulation_3(const Gt&, CGAL::Delaunay_triangulation_3<Gt, Tds_, CGAL::Default, Lock_data_structure_>::Lock_data_structure*) [with Gt = CGAL::Epick; Tds_ = CGAL::Triangulation_data_structure_3<CGAL::Alpha_shape_vertex_base_3<CGAL::Epick>, CGAL::Alpha_shape_cell_base_3<CGAL::Epick> >; Lock_data_structure_ = CGAL::Default; CGAL::Delaunay_triangulation_3<Gt, Tds_, CGAL::Default, Lock_data_structure_>::Lock_data_structure = void]’
./CGAL/Alpha_shape_3.h:263:51: required from ‘CGAL::Alpha_shape_3<Dt, ExactAlphaComparisonTag>::Alpha_shape_3(const InputIterator&, const InputIterator&, const NT&, CGAL::Alpha_shape_3<Dt, ExactAlphaComparisonTag>::Mode) [with InputIterator = std::_List_iterator<CGAL::Point_3<CGAL::Epick> >; Dt = CGAL::Delaunay_triangulation_3<CGAL::Epick, CGAL::Triangulation_data_structure_3<CGAL::Alpha_shape_vertex_base_3<CGAL::Epick>, CGAL::Alpha_shape_cell_base_3<CGAL::Epick> > >; ExactAlphaComparisonTag = CGAL::Boolean_tag<false>; CGAL::Alpha_shape_3<Dt, ExactAlphaComparisonTag>::NT = double]’
diag.cpp:680:65: required from here
./CGAL/Triangulation_ds_cell_base_3.h:166:39: error: ‘class CGAL::Alpha_shape_cell_base_3<CGAL::Epick, CGAL::Triangulation_cell_base_3<CGAL::Epick, CGAL::Triangulation_ds_cell_base_3<CGAL::Triangulation_data_structure_3<CGAL::Alpha_shape_vertex_base_3<CGAL::Epick>, CGAL::Alpha_shape_cell_base_3<CGAL::Epick> > > >, CGAL::Boolean_tag<false>, CGAL::Boolean_tag<false> >’ has no member named ‘operator()’
CGAL_triangulation_precondition(this != n->operator());
^
./CGAL/triangulation_assertions.h:130:20: note: in definition of macro ‘CGAL_triangulation_precondition’
(CGAL::possibly(EX)?(static_cast<void>(0)): ::CGAL::precondition_fail( # EX
^
/usr/lib/R/etc/Makeconf:168: recipe for target 'diag.o' failed
make: *** [diag.o] Error 1
ERROR: compilation failed for package ‘TDA’
* removing ‘/usr/local/lib/R/site-library/TDA’
The downloaded source packages are in
‘/tmp/RtmpFqA1Fu/downloaded_packages’
Warning message:
In install.packages("TDA") :
installation of package ‘TDA’ had non-zero exit status
>
TDA v1.5.1 has the same issue on my Linux servers. Try install a previous version:
install.packages("devtools")
require(devtools);
install_version('TDA', version='1.4.1')

Rcpp Compilation ERROR: 'clang: error: no such file or directory: '/usr/local/lib/libfontconfig.a'

I was trying to run this peace of code in R (credit to the author):
require(Rcpp)
require(RcppArmadillo)
require(inline)
cosineRcpp <- cxxfunction(
signature(Xs = "matrix"),
plugin = c("RcppArmadillo"),
body='
Rcpp::NumericMatrix Xr(Xs); // creates Rcpp matrix from SEXP
int n = Xr.nrow(), k = Xr.ncol();
arma::mat X(Xr.begin(), n, k, false); // reuses memory and avoids extra copy
arma::mat Y = arma::trans(X) * X; // matrix product
arma::mat res = (1 - Y / (arma::sqrt(arma::diagvec(Y)) * arma::trans(arma::sqrt(arma::diagvec(Y)))));
return Rcpp::wrap(res);
')
And got, after few fixes, the following error:
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created!
clang: error: no such file or directory: '/usr/local/lib/libfontconfig.a'
clang: error: no such file or directory: '/usr/local/lib/libreadline.a'
make: *** [file5a681e35ebe1.so] Error 1
In addition: Warning message:
running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file5a681e35ebe1.cpp 2> file5a681e35ebe1.cpp.err.txt' had status 1
I used to use Rcpp a lot in the past. But between now and then my computer has been reformatted and all the installation re-done using homebrew.
I installed cairo with brew: brew install cairo
the libreadline.a error was solved with:
brew link --force readline
But the same did not work for libfontconfig.a since was already linked:
brew link --force fontconfig
Warning: Already linked: /usr/local/Cellar/fontconfig/2.11.1
To relink: brew unlink fontconfig && brew link fontconfig
I would have assumed that fontconfig is within cairo. In fact, when I type
brew install fontconfig
Warning: fontconfig-2.11.1 already installed
But the truth is that there is no libfontconfig.a at /usr/local/lib/:
ls /usr/local/lib/libfont*
/usr/local/lib/libfontconfig.1.dylib
/usr/local/lib/libfontconfig.dylib
Using the very questionable approach of going here and download it, the code runs, but still gives a the corresponding warning, since the file corresponds to a different os.x architecture (I did not found one for 10.9):
+ . + ld: warning: ignoring file /usr/local/lib/libfontconfig.a, missing required architecture x86_64 in file /usr/local/lib/libfontconfig.a (2 slices)
So at this stage I am a little lost.
How do I install libfontconfig.a or find the 10.9 version?
In case is of any use, I have Xcode installed, I am on a Mac 10.9.5,
and based on this very nice and detailed answer my ~/.R/Makevars file looks like:
CC=clang
CXX=clang++
FLIBS=-L/usr/local/bin/
Your system setup is broken. Neither R nor Rcpp have anything to do with clang (unless you chose clang as your system compiler) or fontconfig.
So start simpler:
R> library(Rcpp)
R> evalCpp("2 + 2")
[1] 4
R>
This just showed that my system has a working compiler R (and Rcpp) can talk to. We can it more explicit:
R> evalCpp("2 + 2", verbose=TRUE)
Generated code for function definition:
--------------------------------------------------------
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
SEXP get_value(){ return wrap( 2 + 2 ) ; }
No rebuild required (use rebuild = TRUE to force a rebuild)
[1] 4
R>
and R is clever enough not to rebuild. We can then force a build
R> evalCpp("2 + 2", verbose=TRUE, rebuild=TRUE)
Generated code for function definition:
--------------------------------------------------------
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
SEXP get_value(){ return wrap( 2 + 2 ) ; }
Generated extern "C" functions
--------------------------------------------------------
#include <Rcpp.h>
// get_value
SEXP get_value();
RcppExport SEXP sourceCpp_0_get_value() {
BEGIN_RCPP
Rcpp::RObject __result;
Rcpp::RNGScope __rngScope;
__result = Rcpp::wrap(get_value());
return __result;
END_RCPP
}
Generated R functions
-------------------------------------------------------
`.sourceCpp_0_DLLInfo` <- dyn.load('/tmp/Rtmpeuaiu4/sourcecpp_6a7c7c8295fc/sourceCpp_2.so')
get_value <- Rcpp:::sourceCppFunction(function() {}, FALSE, `.sourceCpp_0_DLLInfo`, 'sourceCpp_0_get_value')
rm(`.sourceCpp_0_DLLInfo`)
Building shared library
--------------------------------------------------------
DIR: /tmp/Rtmpeuaiu4/sourcecpp_6a7c7c8295fc
/usr/lib/R/bin/R CMD SHLIB -o 'sourceCpp_2.so' --preclean 'file6a7c6d1fc2d6.cpp'
ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/tmp/Rtmpeuaiu4" -fpic -g -O3 -Wall -pipe -Wno-unused -pedantic -c file6a7c6d1fc2d6.cpp -o file6a7c6d1fc2d6.o
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o sourceCpp_2.so file6a7c6d1fc2d6.o -L/usr/lib/R/lib -lR
[1] 4
R>
and on that you see system details on my side (Linux, also using ccache) that will be different for you.
After that, try (Rcpp)Armadillo one-liners and so on.

Resources