On Thu, Nov 6, 2008 at 11:29 AM, Whit Armstrong <[EMAIL PROTECTED]>wrote:
> did you wrap your function prototype in extern "C" ?
>
> -Whit
>
>
>
Hi Whit,
Thanks for replying my question. I already gave up my own code and now I am
trying with the examples from SWIG Doc 1.3. I can not even reproduce one of
their examples in section 5.4.9. I wonder if you can have a look at my code
and figure out what's wrong there for me. I used the extern "C" this time
and the details is as following:
---------test.i--------------
%module test
%{
#include "test.h"
%}
%include "test.h"
%callback("%s_cb");
int myadd( int, int ); //myadd_cb
int mysub( int, int ); //mysub_cb
int mymul( int, int ); //mymul_cb
%nocallback;
--------------------------------
-----------test.h--------------
extern "C"{
int binary_op(int a, int b, int (*op)(int,int) );
int myadd( int a, int b ) { return a+b; };
int mysub( int a, int b ) { return a-b; };
int mymul( int a, int b ) { return a*b; };
}
---------------------------------
------error message----------
> dyn.load("test.so")
Error in dyn.load("test.so") :
unable to load shared library '/home/charlie/workspace/lla/test.so':
/home/charlie/workspace/lla/test.so: undefined symbol: binary_op
----------------------------------
------compiling message------
swig -v -r -c++ -o test_wrap.cpp test.i
LangSubDir: r
Search paths:
./
./swig_lib/r/
/usr/local/share/swig/1.3.36/r/
./swig_lib/
/usr/local/share/swig/1.3.36/
Preprocessing...
Starting language-specific parse...
Processing types...
C++ analysis...
Generating wrappers...
Type: p.f(int,int).int
Return type: int
R CMD SHLIB test.cpp test_wrap.cpp
make[1]: Entering directory `/home/charlie/workspace/lla'
g++ -I/usr/local/lib/R/include -I/usr/local/lib/R/include
-I/usr/local/include -fpic -g -O2 -c test_wrap.cpp -o test_wrap.o
g++ -shared -L/usr/local/lib -o test.so test.o test_wrap.o
make[1]: Leaving directory `/home/charlie/workspace/lla'
------------------------------------------
Many thanks!
Charlie
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel