[Rd] Compiling a Tcl extension for an R package
Adrian Waddell
adrian at waddell.ch
Tue Feb 8 19:06:15 CET 2011
Dear R developers,
I plan to upload a first version of my R package RnavGraph to the R CRAN
server in a week or two. However I'm still struggling with an image
resizing function written in C as a tcl extension. I did all my
development in Ubuntu, and everything works fine in Ubuntu, however my
attempts to compile this C function under Windows or OSX have all failed.
I provide a minimal self contained example at the end of this post. I
also wrapped this example in a minimal R package (less than 20 lines of
code!) and it can be downloaded at
http://www.waddell.ch/RnavGraph/TclHelloWorld.zip
Can somebody help me to get this package to compile correctly under
Linux, Windows and OSX? (i.e. writing a configure script with the
correct compile commands).
Thanks,
Adrian Waddell
###########################
C Code (save as hello.c):
#include <tcl.h>
static int Hello_Cmd(ClientData cdata, Tcl_Interp *interp, int objc,
Tcl_Obj *const objv[]) {
Tcl_SetObjResult(interp, Tcl_NewStringObj("Hello, World!", -1));
return TCL_OK;
}
int DLLEXPORT Hello_Init(Tcl_Interp *interp) {
Tcl_CreateObjCommand(interp, "hello", Hello_Cmd, NULL, NULL);
return TCL_OK;
}
which can be compiled (under Ubuntu 10.04) with:
gcc -shared -o hello.so -DUSE_TCL_STUBS -I/usr/include/tcl8.5/ hello.c
-L/usr/lib/ -ltclstub8.5 -fPIC
and used within an R session with
library(tcltk)
.Tcl('load ./hello[info sharedlibextension]')
tcl('hello')
More information about the R-devel
mailing list