From: Douglas H. <dh...@gm...> - 2008-01-30 20:42:00
|
Hi, I have been trying to get swig to make some R bindings for a C++ project of mine and ran into some build errors. I then created a simple test class called RTest, including only a constructor and a member function and I'm getting the following errors (which are similar in nature to what I was getting with my larger project): dhains@tessier:~/code/swig/R$ swig -c++ -r -o rtest_wrap.cpp rtest.i dhains@tessier:~/code/swig/R$ PKG_LIBS="rtest.cpp" R CMD SHLIB rtest_wrap.cpp g++ -I/usr/share/R/include -I/usr/share/R/include -fpic -g -O2 -c rtest_wrap.cpp -o rtest_wrap.o rtest_wrap.cpp: In function 'RCallbackFunctionData* R_SWIG_pushCallbackFunctionData(SEXPREC*, SEXPREC*)': rtest_wrap.cpp:759: error: 'calloc' was not declared in this scope rtest_wrap.cpp: In function 'void R_SWIG_popCallbackFunctionData(int)': rtest_wrap.cpp:800: error: 'free' was not declared in this scope rtest_wrap.cpp: In function 'void R_SWIG_ReferenceFinalizer(SEXPREC*)': rtest_wrap.cpp:888: error: 'free' was not declared in this scope rtest_wrap.cpp: In function 'SEXPREC* RSwigPacked_New(void*, size_t, swig_type_info*)': rtest_wrap.cpp:1000: error: 'malloc' was not declared in this scope rtest_wrap.cpp: In function 'SEXPREC* R_swig_new_RTest(SEXPREC*, SEXPREC*)': rtest_wrap.cpp:1246: error: invalid conversion from 'void*' to 'char*' rtest_wrap.cpp: In function 'SEXPREC* R_swig_RTest_mult(SEXPREC*, SEXPREC*)': rtest_wrap.cpp:1268: error: invalid conversion from 'void*' to 'char*' rtest_wrap.cpp: In function 'SEXPREC* R_swig_delete_RTest(SEXPREC*)': rtest_wrap.cpp:1292: error: invalid conversion from 'void*' to 'char*' make: *** [rtest_wrap.o] Error 1 I can #include <cstdlib> to get rid of the malloc errors and reinterpret_cast<char*> to fix the invalid conversion errors. It then compiles and creates the so. It doesn't seem like I should have to do this, am I doing something wrong or is C++ support within the R module lacking? Thanks! |
From: William S F. <ws...@fu...> - 2008-01-30 22:20:21
|
Douglas Hains wrote: > Hi, I have been trying to get swig to make some R bindings for a C++ > project of mine and ran into some build errors. I then created a > simple test class called RTest, including only a constructor and a > member function and I'm getting the following errors (which are > similar in nature to what I was getting with my larger project): > > dhains@tessier:~/code/swig/R$ swig -c++ -r -o rtest_wrap.cpp rtest.i > dhains@tessier:~/code/swig/R$ PKG_LIBS="rtest.cpp" R CMD SHLIB rtest_wrap.cpp > > g++ -I/usr/share/R/include -I/usr/share/R/include -fpic -g -O2 > -c rtest_wrap.cpp -o rtest_wrap.o > rtest_wrap.cpp: In function 'RCallbackFunctionData* > R_SWIG_pushCallbackFunctionData(SEXPREC*, SEXPREC*)': > rtest_wrap.cpp:759: error: 'calloc' was not declared in this scope > rtest_wrap.cpp: In function 'void R_SWIG_popCallbackFunctionData(int)': > rtest_wrap.cpp:800: error: 'free' was not declared in this scope > rtest_wrap.cpp: In function 'void R_SWIG_ReferenceFinalizer(SEXPREC*)': > rtest_wrap.cpp:888: error: 'free' was not declared in this scope > rtest_wrap.cpp: In function 'SEXPREC* RSwigPacked_New(void*, size_t, > swig_type_info*)': > rtest_wrap.cpp:1000: error: 'malloc' was not declared in this scope > rtest_wrap.cpp: In function 'SEXPREC* R_swig_new_RTest(SEXPREC*, SEXPREC*)': > rtest_wrap.cpp:1246: error: invalid conversion from 'void*' to 'char*' > rtest_wrap.cpp: In function 'SEXPREC* R_swig_RTest_mult(SEXPREC*, SEXPREC*)': > rtest_wrap.cpp:1268: error: invalid conversion from 'void*' to 'char*' > rtest_wrap.cpp: In function 'SEXPREC* R_swig_delete_RTest(SEXPREC*)': > rtest_wrap.cpp:1292: error: invalid conversion from 'void*' to 'char*' > make: *** [rtest_wrap.o] Error 1 > > I can #include <cstdlib> to get rid of the malloc errors and > reinterpret_cast<char*> to fix the invalid conversion errors. It then > compiles and creates the so. It doesn't seem like I should have to do > this, am I doing something wrong or is C++ support within the R module > lacking? > Very strange, all the C++ tests work fine. Are you using the latest version of swig? If so, you should the following around line 730 of the wrappers: /* Remove global namespace pollution */ #if !defined(SWIG_NO_R_NO_REMAP) # define R_NO_REMAP #endif #if !defined(SWIG_NO_STRICT_R_HEADERS) # define STRICT_R_HEADERS #endif #include <Rdefines.h> #include <Rversion.h> #include <stdlib.h> #define SWIGR 1 You can see the stdlib.h include. If you are still having problems, you'd better give the versions of the tools and OS. William |