From armstrong.whit at gmail.com  Thu Nov  6 20:29:25 2008
From: armstrong.whit at gmail.com (Whit Armstrong)
Date: Thu, 6 Nov 2008 14:29:25 -0500
Subject: [Rd] Fwd: SWIG with R and C++ STL
In-Reply-To: <11c6cf4e0811061016r4dc114d8l261948c4512c1e12@mail.gmail.com>
References: <11c6cf4e0811041355v16321693hdd53d2376dc0a8c4@mail.gmail.com>
	<11c6cf4e0811061016r4dc114d8l261948c4512c1e12@mail.gmail.com>
Message-ID: <8ec76080811061129p2e54125eqee948a31bb4a4de8@mail.gmail.com>

did you wrap your function prototype in extern "C" ?

-Whit


On Thu, Nov 6, 2008 at 1:16 PM, charlie <charlie.xia.fdu at gmail.com> wrote:
> Hi, all
>
> I didn't get any response from swig for my question.
> see if I can get some help here
>
> Thanks
>
> ---------- Forwarded message ----------
> From: charlie <charlie.xia.fdu at gmail.com>
> Date: Tue, Nov 4, 2008 at 1:55 PM
> Subject: SWIG with R and C++ STL
> To: swig-user at lists.sourceforge.net
>
>
> Hi all,
>
> I am new to SWIG. I encountered some problem when I try to SWIG to R some
> C++ modules.
> Here is the details. I got "myvector.i" and "myvector.h" as my two input
> files, the contends are:
>
> ---myvector.i-----
> %module myvector
> %{
> #include "myvector.h"
> %}
>
> %include "std_vector.i"
>
> namespace std {
>    %template(IntVector) vector<int>;
>    %template(DoubleVector) vector<double>;
> };
>
> %include "myvector.h"
> ----------------------------------
>
> --myvector.h-------------------
> /* File : example.h */
>
> #include <vector>
> #include <algorithm>
> #include <functional>
> #include <numeric>
>
> double average(std::vector<int> v) {
>      return std::accumulate(v.begin(),v.end(),0.0)/v.size();
> }
>
> std::vector<double> half(const std::vector<double>& v) {
>      std::vector<double> w(v);
>          for (unsigned int i=0; i<w.size(); i++)
>                    w[i] /= 2.0;
>              return w;
> }
>
> void halve_in_place(std::vector<double>& v) {
>      std::transform(v.begin(),v.end(),v.begin(),
>                             std::bind2nd(std::divides<double>(),2.0));
> }
> -------------------------------------
>
> Basicly they are just examples from the SWIG doc.
> And I ran:
> *swig -c++ -r -o myvector_wrap.cpp myvector.i
> PKG_LIBS="myvector.h" R CMD SHLIB myvector_wrap.cpp*
> Then in R I ran:
>>*dyn.load("myvector.so")*
>>*source("myvector.R")*
> Then i tried to create a vector in R:
>>*vi=IntVector(4)*
> I go the following error:
> *Error in .Call("R_swig_new_IntVector__SWIG_2", size, PACKAGE="myvector"):
>  C symbol name "R_swig_new_IntVector__SWIG_2" not in DLL for package
> "myvector"*
>
> Since I basicly followed the steps in the doc, I don't understand where the
> error comes from.
> Can anybody help me out?
>
> Thanks a lot!
>
> Charlie
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] Fwd: SWIG with R and C++ STL
Whit Armstrong