I am trying to build an R package that uses some C code. I have a C library that is compiled into an executable, that can be called from the command line. There is a Makefile as
callable.c
#include
int main(int argc, char **argv) {
printf("Hello World\n");
return 0;
}
To get a .so file from the C file callable.c use
R CMD SHLIB callable.c
So now we have callable.so
R normally requires that all C arguments be pointers, but if your main method ignores argc, then we can get around this. So to call main from callable.so from R we can write a method like so.
main <- function() {
dyn.load("callable.so")
out <- .C("main", argc=0, argv="")
}
Calling that main function will run the C main function.