I have just quick question about how to compile a .cpp file with multiple function in it.
Let's say I have c++ file like this : Functions.cpp
#include <Rcpp.h>
#include <math.h> /* pow */
using namespace Rcpp;
// [[Rcpp::export]]
int Function1 (int N, NumericMatrix W){
return ....
}
// [[Rcpp::export]]
int Function2 (int N, NumericMatrix W){
return ....
}
and then I would like to compile the file and be able to to call both functions.
I have done it, but what happens is when I try to load the Functions.o it gives me this":
Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared object 'C:/Users/Functions.o':
LoadLibrary failure: %1 is not a valid Win32 application.
Anybody , any idea ?
Just use sourceCpp("nameofyourfile.cpp")
If you you have no syntax error preventing compilation both Function1 and Function2 will be accessible in your R session.
Literally thousands of such files have been written, and almost one hundred are at your disposal over at the Rcpp Gallery.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I have some functions written in Rcpp and RcppArmadillo like this
example.cpp:
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
#include <iostream>
#include <math.h>
using namespace Rcpp;
// using namespace RcppArmadillo;
using namespace arma;
using namespace std;
// [[Rcpp::export]]
double inner1(NumericVector x, NumericVector y) {
int K = x.length() ;
double ip = 0 ;
for (int k = 0 ; k < K ; k++) {
ip += x(k) * y(k) ;
}
return(ip) ;
}
// [[Rcpp::export]]
mat multiply2(mat A, mat B) {
return A * B;
}
Then I use Rcpp::sourceCpp('example.cpp') and It works well under Ubuntu.
(I have run library(Rcpp) and library(RcppArmadillo) before )
However, When I move to Windows Platform, the RStudio Throw an error said:
> Rcpp::sourceCpp('R:/example.cpp')
Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared object 'C:/Users/[Username]/AppData/Local/Temp/RtmpG6H80X/sourceCpp-x86_64-w64-mingw32-0.12.19/sourcecpp_40b04b2c2bcf/sourceCpp_4.dll':
LoadLibrary failure: The specified procedure could not be found.
I found the key problem is in the matrix multiplication. Since I try to delete the second function multiply2. Then the rest of the code can be complied successfully under Windows.
example2.cpp
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
#include <iostream>
#include <math.h>
using namespace Rcpp;
// using namespace RcppArmadillo;
using namespace arma;
using namespace std;
// [[Rcpp::export]]
double inner1(NumericVector x, NumericVector y) {
int K = x.length() ;
double ip = 0 ;
for (int k = 0 ; k < K ; k++) {
ip += x(k) * y(k) ;
}
return(ip) ;
}
I have tried some other codes, found that this error occurs when matrix multiplication * was used in code.
So, Why matrix multiplication in RcppArmadillo fails under Windows Platform?
After the struggled with the compiler for a long time, I found the key point is the BLAS library was not correctly set in my windows system environment path.
In short, the solution is :
Download precompiled binary packages of OpenBLS at Here (DO NOT try to compile the newest version under windows, I've waste a lot time on it)
Exactor OpenBLAS-v0.2.19-Win64-int32.zip to some where like C:\LIBS\OpenBLAS-v0.2.15-Win64-int32
Add C:\LIBS\OpenBLAS-v0.2.15-Win64-int32\bin to your PATH
[Optional] Create a new environment variable called BLAS_LIBS, which value is C:\LIBS\OpenBLAS-v0.2.15-Win64-int32\bin
Restart RStudio, and the problem was solved.
I find this solution by install RcppArmadillo from source by install.packages("RcppArmadillo", type = "source"), this time the RStudio throw the same error during the compiling, so the install fails.
However, if I just use install.packages("RcppArmadillo"), the RStudio will install binary version of RcppArmadillo, so I didn't get any feedback about the absence of BLAS.
As described in the post:
Rcpp and boost: it should work but it does not
I am trying to use boost in Rcpp in Windows. The (simplified) file is:
// [[Rcpp::depends(BH)]]
#include <Rcpp.h>
#include <boost/multiprecision/float128.hpp>
namespace mp = boost::multiprecision;
// [[Rcpp::export]]
std::string qexp(double da = -1500.0, double db = -1501.0)
{
mp::float128 a(da), b(db);
mp::float128 res = mp::exp(a) / (mp::exp(a) + mp::exp(b));
return res.convert_to<std::string>();
}
I had a compile problem. As #duckmayr suggested in that post, I tried with:
Sys.setenv("PKG_LIBS" = "-lquadmath")
and then Rcpp::sourceCpp('quadexp.cpp')
In this way, the compilation runs without errors. But then, when I execute qexp(), I get a message in RStudio about "fatal error", and RStudio shuts down completely. Do you know what could be happening? I assume my problem is due to some kind of configuration I have, since #duckmayr could run the same code without problems. What parts of my configuration should look at, in order to avoid this nasty "fatal error"?
In addition to the comment above:
edd#rob:~/git/so-r/52933795$ cat code.cpp
// [[Rcpp::depends(BH)]]
#include <Rcpp.h>
#include <boost/multiprecision/float128.hpp>
namespace mp = boost::multiprecision;
// [[Rcpp::export]]
std::string qexp(double da = -1500.0, double db = -1501.0) {
mp::float128 a(da), b(db);
mp::float128 res = mp::exp(a) / (mp::exp(a) + mp::exp(b));
return res.convert_to<std::string>();
}
/*** R
qexp()
*/
edd#rob:~/git/so-r/52933795$ Rscript -e 'Rcpp::sourceCpp("code.cpp")'
R> qexp()
[1] "0.731058578630004879251159241821836351"
edd#rob:~/git/so-r/52933795$
I.e. using exactly your code (plus an added R invocation) it just works "as is".
When I submit my package to cran I get the error as
Found no calls to: 'R_registerRoutines', 'R_useDynamicSymbols'
It is good practice to register native routines and to disable symbol
search.
My package was tested in this version of R by CRAN:
R version 3.4.0 alpha (2017-03-28 r72427)
Note that there is a solution for this error here
R CMD check note: Found no calls to: ‘R_registerRoutines’, ‘R_useDynamicSymbols’
but my external codes are in Fortran and tried the procedure described there but does not fix the issue for me. What can I do to overcome the issue?
Thanks
Update:
Following the procedure described https://www.r-bloggers.com/1-easy-package-registration/ I could pass the
Error:Found no calls to: ‘R_useDynamicSymbols’
But Found no call to: 'R_registerRoutines' still remains.
I solved the problem and you may find it useful for your own case.
Let's assume you have a subroutine called myf.f90 in src directory with following content:
SUBROUTINE cf(r,cd,loci)
INTEGER::r,cd
DOUBLE PRECISION::loci
....
....
....
END SUBROUTINE cf
To register this you need to do the following :
A) Run tools::package_native_routine_registration_skeleton("package directory")
B) Edit the output; for the example above would be:
#include <R.h>
#include <Rinternals.h>
#include <stdlib.h> // for NULL
#include <R_ext/Rdynload.h>
/* FIXME:
Check these declarations against the C/Fortran source code.
*/
/* .Fortran calls */
extern void F77_NAME(cf)(int *r, int *cd, double *loci);
static const R_FortranMethodDef FortranEntries[] = {
{"cf", (DL_FUNC) &F77_NAME(cf), 3},
{NULL, NULL, 0}
};
void R_init_packagename(DllInfo *dll)
{
R_registerRoutines(dll, NULL, NULL, FortranEntries, NULL);
R_useDynamicSymbols(dll, FALSE);
}
C) Copy and paste the full output in a packagename_init.c file to be put in src/
D) Update NAMESPACE, verifying that useDynLib(packagename, .registration = TRUE)
I have dynamic library created as follows
cat myfile.cc
struct Tcl_Interp;
extern "C" int My_Init(Tcl_Interp *) { return 0; }
1) complile the cc file
g++ -fPIC -c myfile.cc
2) Creating a shared library
g++ -static-libstdc++ -static-libgcc -shared -o libmy.so myfile.o -L/tools/linux64/qt-4.6.0/lib -lQtCore -lQtGui
3) load the library from a TCL proc
then I give command
tclsh
and given command
% load libmy.so
is there any C++ function/ Qt equivalent to load that can load the shared library on demand from another C++ function.
My requirement is to load the dynamic library on run time inside the function and then use the qt functions directly
1) load the qt shared libraries (for lib1.so)
2) call directly the functions without any call for resolve
For example we have dopen, but for that for each function call we have to call dsym. My requirement is only call for shared library then directly call those functions.
You want boilerplate-less delay loading. On Windows, MSVC implements delay loading by emitting a stub that resolves the function through a function pointer. You can do the same. First, let's observe that function pointers and functions are interchangeable if all you do is call them. The syntax for invoking a function or a function pointer is the same:
void foo_impl() {}
void (*foo)() = foo_impl;
int main() {
foo_impl();
foo();
}
The idea is to set the function pointer initially to a thunk that will resolve the real function at runtime:
extern void (*foo)();
void foo_thunk() {
foo = QLibrary::resolve("libmylib", "foo");
if (!foo) abort();
return foo();
}
void (*foo)() = foo_thunk;
int main() {
foo(); // calls foo_thunk to resolve foo and calls foo from libmylib
foo(); // calls foo from libmylib
}
When you first call foo, it will really call foo_thunk, resolve the function address, and call real foo implementation.
To do this, you can split the library into two libraries:
The library implementation. It is unaware of demand-loading.
A demand-load stub.
The executable will link to the demand-load stub library; that is either static or dynamic. The demand-load stub will automatically resolve the symbols at runtime and call into the implementation.
If you're clever, you can design the header for the implementation such that the header itself can be used to generate all the stubs without having to enter their details twice.
Complete Example
Everything follows, it's also available from https://github.com/KubaO/stackoverflown/tree/master/questions/demand-load-39291032
The top-level project consists of:
lib1 - the dynamic library
lib1_demand - the static demand-load thunk for lib1
main - the application that uses lib1_demand
demand-load-39291032.pro
TEMPLATE = subdirs
SUBDIRS = lib1 lib1_demand main
main.depends = lib1_demand
lib1_demand.depends = lib1
We can factor out the cleverness into a separate header. This header allows us to define the library interface so that the thunks can be automatically generated.
The heavy use of preprocessor and a somewhat redundant syntax is needed due to limitations of C. If you wanted to implement this for C++ only, there'd be no need to repeat the argument list.
demand_load.h
// Configuration macros:
// DEMAND_NAME - must be set to a unique identifier of the library
// DEMAND_LOAD - if defined, the functions are declared as function pointers, **or**
// DEMAND_BUILD - if defined, the thunks and function pointers are defined
#if defined(DEMAND_FUN)
#error Multiple inclusion of demand_load.h without undefining DEMAND_FUN first.
#endif
#if !defined(DEMAND_NAME)
#error DEMAND_NAME must be defined
#endif
#if defined(DEMAND_LOAD)
// Interface via a function pointer
#define DEMAND_FUN(ret,name,args,arg_call) \
extern ret (*name)args;
#elif defined(DEMAND_BUILD)
// Implementation of the demand loader stub
#ifndef DEMAND_CAT
#define DEMAND_CAT_(x,y) x##y
#define DEMAND_CAT(x,y) DEMAND_CAT_(x,y)
#endif
void (* DEMAND_CAT(resolve_,DEMAND_NAME)(const char *))();
#if defined(__cplusplus)
#define DEMAND_FUN(ret,name,args,arg_call) \
extern ret (*name)args; \
ret name##_thunk args { \
name = reinterpret_cast<decltype(name)>(DEMAND_CAT(resolve_,DEMAND_NAME)(#name)); \
return name arg_call; \
}\
ret (*name)args = name##_thunk;
#else
#define DEMAND_FUN(ret,name,args,arg_call) \
extern ret (*name)args; \
ret name##_impl args { \
name = (void*)DEMAND_CAT(resolve_,DEMAND_NAME)(#name); \
name arg_call; \
}\
ret (*name)args = name##_impl;
#endif // __cplusplus
#else
// Interface via a function
#define DEMAND_FUN(ret,name,args,arg_call) \
ret name args;
#endif
Then, the dynamic library itself:
lib1/lib1.pro
TEMPLATE = lib
SOURCES = lib1.c
HEADERS = lib1.h
INCLUDEPATH += ..
DEPENDPATH += ..
Instead of declaring the functions directly, we'll use DEMAND_FUN from demand_load.h. If DEMAND_LOAD_LIB1 is defined when the header is included, it will offer a demand-load interface to the library. If DEMAND_BUILD is defined, it'll define the demand-load thunks. If neither is defined, it will offer a normal interface.
We take care to undefine the implementation-specific macros so that the global namespace is not polluted. We can then include multiple libraries the project, each one individually selectable between demand- and non-demand loading.
lib1/lib1.h
#ifndef LIB_H
#define LIB_H
#ifdef __cplusplus
extern "C" {
#endif
#define DEMAND_NAME LIB1
#ifdef DEMAND_LOAD_LIB1
#define DEMAND_LOAD
#endif
#include "demand_load.h"
#undef DEMAND_LOAD
DEMAND_FUN(int, My_Add, (int i, int j), (i,j))
DEMAND_FUN(int, My_Subtract, (int i, int j), (i,j))
#undef DEMAND_FUN
#undef DEMAND_NAME
#ifdef __cplusplus
}
#endif
#endif
The implementation is uncontroversial:
lib1/lib1.c
#include "lib1.h"
int My_Add(int i, int j) {
return i+j;
}
int My_Subtract(int i, int j) {
return i-j;
}
For the user of such a library, demand loading is reduced to defining one macro and using the thunk library lib1_demand instead of the dynamic library lib1.
main/main.pro
if (true) {
# Use demand-loaded lib1
DEFINES += DEMAND_LOAD_LIB1
LIBS += -L../lib1_demand -llib1_demand
} else {
# Use direct-loaded lib1
LIBS += -L../lib1 -llib1
}
QT = core
CONFIG += console c++11
CONFIG -= app_bundle
TARGET = demand-load-39291032
TEMPLATE = app
INCLUDEPATH += ..
DEPENDPATH += ..
SOURCES = main.cpp
main/main.cpp
#include "lib1/lib1.h"
#include <QtCore>
int main() {
auto a = My_Add(1, 2);
Q_ASSERT(a == 3);
auto b = My_Add(3, 4);
Q_ASSERT(b == 7);
auto c = My_Subtract(5, 7);
Q_ASSERT(c == -2);
}
Finally, the implementation of the thunk. Here we have a choice between using dlopen+dlsym or QLibrary. For simplicity, I opted for the latter:
lib1_demand/lib1_demand.pro
QT = core
TEMPLATE = lib
CONFIG += staticlib
INCLUDEPATH += ..
DEPENDPATH += ..
SOURCES = lib1_demand.cpp
HEADERS = ../demand_load.h
lib1_demand/lib1_demand.cpp
#define DEMAND_BUILD
#include "lib1/lib1.h"
#include <QLibrary>
void (* resolve_LIB1(const char * name))() {
auto f = QLibrary::resolve("../lib1/liblib1", name);
return f;
}
Quite apart from the process of loading a library into your C++ code (which Kuber Ober's answer covers just fine) the code that you are loading is wrong; even if you manage to load it, your code will crash! This is because you have a variable of type Tcl_Interp at file scope; that's wrong use of the Tcl library. Instead, the library provides only one way to obtain a handle to an interpreter context, Tcl_CreateInterp() (and a few other functions that are wrappers round it), and that returns a Tcl_Interp* that has already been initialised correctly. (Strictly, it actually returns a handle to what is effectively an internal subclass of Tcl_Interp, so you really can't usefully allocate one yourself.)
The correct usage of the library is this:
Tcl_FindExecutable(NULL); // Or argv[0] if you have it
Tcl_Interp *interp = Tcl_CreateInterp();
// And now, you can use the rest of the API as you see fit
That's for putting a Tcl interpreter inside your code. To do it the other way round, you create an int My_Init(Tcl_Interp*) function as you describe and it is used to tell you where the interpreter is, but then you wouldn't be asking how to load the code, as Tcl has reasonable support for that already.
I am attempting to use the Rcpp11 package in r from it's source over at:
devtools::install_github("Rcpp11/Rcpp11")
I read here: http://blog.r-enthusiasts.com/2014/05/27/disambiguating-rcpp11-and-rcpp/
that I can use include <Rcpp11> + using namespace Rcpp11 at the head of my .cpp file but I get this error upon sourcing:
egfile.cpp:1:10: fatal error: 'Rcpp11' file not found
#include <Rcpp11>
^
1 error generated.
where egfile.cpp:
#include <Rcpp11>
using namespace Rcpp11;
// Below is a simple example of exporting a C++ function to R. You can
// source this function into an R session using the Rcpp::sourceCpp
// function (or via the Source button on the editor toolbar)
// For more on using Rcpp click the Help button on the editor toolbar
// [[Rcpp::export]]
int timesTwo(int x) {
return x * 2;
}
Any help with this? or should I defer to the // [[Rcpp::plugins(cpp11)]] method ?
Update: using the attributes::sourceCpp()
devtools::install_github("Rcpp11/attributes")
then restart from a clean session:
library(Rcpp11)
attributes::sourceCpp("egfile.cpp") # in home directory.
I get:
In file included from file2c1e303c4ed6.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp11:4:
In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp.h:238:
/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:54:1: error: no member named 'Rf_pnorm' in the global namespace
RCPP_DPQ__2(norm,double mean = 0, double sd = 1, mean, sd )
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:30:51: note: expanded from macro 'RCPP_DPQ__2'
#define RCPP_DPQ__2(__NAME__,PAR1,PAR2,VAL1,VAL2) RCPP_DPQ(__NAME__,RCPP_ECHO(RCPP_CONCAT(PAR1,PAR2)), RCPP_ECHO(RCPP_CONCAT(VAL1,VAL2)) )
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:14:31: note: expanded from macro 'RCPP_DPQ'
decltype(sapply( x, ::Rf_p##__NAME__, VAL, lower, log )) \
~~^
<scratch space>:208:1: note: expanded from here
Rf_pnorm
^
In file included from file2c1e303c4ed6.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp11:4:
In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp.h:238:
/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:54:1: error: no member named 'Rf_pnorm' in the global namespace
RCPP_DPQ__2(norm,double mean = 0, double sd = 1, mean, sd )
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:30:51: note: expanded from macro 'RCPP_DPQ__2'
#define RCPP_DPQ__2(__NAME__,PAR1,PAR2,VAL1,VAL2) RCPP_DPQ(__NAME__,RCPP_ECHO(RCPP_CONCAT(PAR1,PAR2)), RCPP_ECHO(RCPP_CONCAT(VAL1,VAL2)) )
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:16:29: note: expanded from macro 'RCPP_DPQ'
return sapply( x, ::Rf_p##__NAME__, VAL, lower, log ) ; \
~~^
<scratch space>:208:1: note: expanded from here
Rf_pnorm
^
In file included from file2c1e303c4ed6.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp11:4:
In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp.h:238:
/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:54:1: error: no member named 'Rf_qnorm' in the global namespace
RCPP_DPQ__2(norm,double mean = 0, double sd = 1, mean, sd )
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:30:51: note: expanded from macro 'RCPP_DPQ__2'
#define RCPP_DPQ__2(__NAME__,PAR1,PAR2,VAL1,VAL2) RCPP_DPQ(__NAME__,RCPP_ECHO(RCPP_CONCAT(PAR1,PAR2)), RCPP_ECHO(RCPP_CONCAT(VAL1,VAL2)) )
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:20:31: note: expanded from macro 'RCPP_DPQ'
decltype(sapply( x, ::Rf_q##__NAME__, VAL, lower, log )) \
~~^
<scratch space>:208:1: note: expanded from here
Rf_qnorm
^
In file included from file2c1e303c4ed6.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp11:4:
In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp.h:238:
/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:54:1: error: no member named 'Rf_qnorm' in the global namespace
RCPP_DPQ__2(norm,double mean = 0, double sd = 1, mean, sd )
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:30:51: note: expanded from macro 'RCPP_DPQ__2'
#define RCPP_DPQ__2(__NAME__,PAR1,PAR2,VAL1,VAL2) RCPP_DPQ(__NAME__,RCPP_ECHO(RCPP_CONCAT(PAR1,PAR2)), RCPP_ECHO(RCPP_CONCAT(VAL1,VAL2)) )
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:22:29: note: expanded from macro 'RCPP_DPQ'
return sapply( x, ::Rf_q##__NAME__, VAL, lower, log ) ; \
~~^
<scratch space>:208:1: note: expanded from here
Rf_qnorm
^
4 errors generated.
make: *** [file2c1e303c4ed6.o] Error 1
Error in dyn.load(basename(dynlib)) :
unable to load shared object '/private/var/folders/77/9nq5hj5d37b1rhbzdt0z3twr0000gn/T/RtmpcjWOsg/file2c1e303c4ed6.so':
dlopen(/private/var/folders/77/9nq5hj5d37b1rhbzdt0z3twr0000gn/T/RtmpcjWOsg/file2c1e303c4ed6.so, 6): image not found
In addition: Warning message:
running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB 'file2c1e303c4ed6.cpp'' had status 1
Presumably, you are trying to compile it from R Studio, which will use Rcpp::sourceCpp. You need the implementation of sourceCpp from the attributes package to generate the glue code for Rcpp11. attributes is available from github:
devtools::install_github("Rcpp11/attributes")
Then use this version to compile your file, i.e.
attributes::sourceCpp( "yourfile.cpp" )
Compiling an Rcpp11 file using Rstudio ui is something we have not yet dealt with, but something we identified as needed here