Fwd: Using SWIG with R

View: New views
3 Messages — Rating Filter:   Alert me  

Parent Message unknown Fwd: Using SWIG with R

by Nathan Harmston-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: Fwd: Using SWIG with R

by John Hayes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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.



------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: Fwd: Using SWIG with R

by wsfulton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user