From: William S F. <ws...@fu...> - 2009-10-06 05:59:36
|
John Hayes wrote: > On Oct 3, 2009, at 6:26 AM, Nathan Harmston wrote: > >> Hi, >> >> I am trying to get SWIG to run to interface some C++ and and R code, >> but I am having a lot of problems. So looking at the tutorial at >> http://www.swig.org/Doc1.3/R.html >> I m using SWIG Version 1.3.31 >> Is SWIG still maintained for use with R? >> >> I am able to run SWIG directly using >> >> swig -c++ -r -o bootstrap_wrap.c bootstrap.i >> >> which seems to generate the correct files, then I try >> PKG_LIBS="bootstrap.cpp" R CMD SHLIB bootstrap_wrap.cpp >> >> and all I seem to get is a >> gcc -arch i386 -std=gnu99 >> -I/Library/Frameworks/R.framework/Resources/include >> -I/Library/Frameworks/R.framework/Resources/include/i386 >> -I/usr/local/include -fPIC -g -O2 -c bootstrap_wrap.c -o >> bootstrap_wrap.o >> bootstrap_wrap.c: In function ‘R_SWIG_pushCallbackFunctionData’: >> bootstrap_wrap.c:759: warning: implicit declaration of function >> ‘calloc’ >> bootstrap_wrap.c:759: warning: incompatible implicit declaration of >> built-in function ‘calloc’ >> bootstrap_wrap.c: In function ‘R_SWIG_popCallbackFunctionData’: >> bootstrap_wrap.c:800: warning: implicit declaration of function ‘free’ >> bootstrap_wrap.c: In function ‘RSwigPacked_New’: >> bootstrap_wrap.c:1000: warning: implicit declaration of function >> ‘malloc’ >> bootstrap_wrap.c:1000: warning: incompatible implicit declaration of >> built-in function ‘malloc’ >> bootstrap_wrap.c:1194:21: error: stdexcept: No such file or directory >> make[1]: *** [bootstrap_wrap.o] Error 1 >> >> >> So how can I compile this correctly is there something in my path >> wrong? or the setup of SWIG is wrong? Is there a better tutorial for >> using R with SWIG than the one above. >> >> Many thanks >> Nathan >> > > I've never used swig with R but I think the problem is the output file > name. You're telling SWIG to make C++ bindings but you're saving it > into a C file. Here is a working version of one of the classic c++ examples which you should be able to repeat: william@caracal:~/swig/trunk$ cd Examples/r/class/ william@caracal:~/swig/trunk/Examples/r/class$ make check make -f ../../Makefile CXXSRCS='example.cxx' SWIG='../../../preinst-swig' \ TARGET='example' INTERFACE='example.i' r_cpp make[1]: Entering directory `/home/william/swig/trunk/Examples/r/class' ../../../preinst-swig -c++ -r -o example_wrap.cpp example.i ( PKG_LIBS="example.cxx" PKG_CPPFLAGS="" R CMD SHLIB -o example.so example_wrap.cpp ) make[2]: Entering directory `/home/william/swig/trunk/Examples/r/class' g++ -I/usr/share/R/include -fpic -g -O2 -c example_wrap.cpp -o example_wrap.o g++ -shared -o example.so example_wrap.o example.cxx -L/usr/lib/R/lib -lR make[2]: Leaving directory `/home/william/swig/trunk/Examples/r/class' make[1]: Leaving directory `/home/william/swig/trunk/Examples/r/class' R CMD BATCH runme.R william@caracal:~/swig/trunk/Examples/r/class$ The output after running is in runme.Rout. William |