Skip to content

Commit

Permalink
Fix running R examples and update docs about R CMD SHLIB
Browse files Browse the repository at this point in the history
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12049 626c5289-ae23-0410-ae9c-e8d60b6d4f22
  • Loading branch information
wsfulton committed May 25, 2010
1 parent ae8ac07 commit 314d4f1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
34 changes: 27 additions & 7 deletions Doc/Manual/R.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,48 @@ <H2><a name="R_nn3"></a>34.2 Using R and SWIG</H2>
<div class="shell">
<pre>
swig -r example.i
PKG_LIBS="example.c" R CMD SHLIB example_wrap.c
R CMD SHLIB example_wrap.c example.c
</pre>
</div>

<p>
The corresponding comments for C++ mode are
The corresponding options for C++ mode are
</p>

<div class="shell">
<pre>
swig -c++ -r -o example_wrap.cpp example.i
PKG_LIBS="example.cxx" R CMD SHLIB example_wrap.cpp
R CMD SHLIB example_wrap.cpp example.cpp
</pre>
</div>

<p>
Note that R is sensitive to the name of the file and to the file
extension in C and C++ mode. The name of the wrapper file must be the
name of the library. Also in C++ mode, the file extension must be .cpp
rather than .cxx for the R compile command to recognize it.
Note that R is sensitive to the names of the files.
The name of the wrapper file must be the
name of the library unless you use the -o option to R when building the library, for example:
</p>

<div class="shell">
<pre>
swig -c++ -r -o example_wrap.cpp example.i
R CMD SHLIB -o example.so example_wrap.cpp example.cpp
</pre>
</div>

<p>
R is also sensitive to the name of the file
extension in C and C++ mode. In C++ mode, the file extension must be .cpp
rather than .cxx for the R compile command to recognize it. If your C++ code is
in a file using something other than a .cpp extension, then it may still work using PKG_LIBS:
</p>

<div class="shell">
<pre>
swig -c++ -r -o example_wrap.cpp example.i
PKG_LIBS="example.cxx" R CMD SHLIB -o example example_wrap.cpp
</pre>
</div>

<p>
The commands produces two files. A dynamic shared object file called
example.so, or example.dll, and an R wrapper file called example.R. To load these
Expand Down
4 changes: 2 additions & 2 deletions Examples/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -1129,11 +1129,11 @@ RRSRC = $(INTERFACE:.i=.R)

r: $(SRCS)
$(SWIG) -r $(SWIGOPT) $(INTERFACEPATH)
+( PKG_LIBS="$(SRCS)" PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -fPIC -o $(LIBPREFIX)$(TARGET)$(SO) $(ISRCS) )
+( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(ISRCS) $(SRCS) )

r_cpp: $(CXXSRCS)
$(SWIG) -c++ -r $(SWIGOPT) -o $(RCXXSRCS) $(INTERFACEPATH)
+( PKG_LIBS="$(CXXSRCS)" PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -fPIC -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) )
+( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(SRCS) $(CXXSRCS))

r_clean:
rm -f *_wrap* *~ .~*
Expand Down
5 changes: 1 addition & 4 deletions Examples/r/class/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ SWIG = $(TOP)/../preinst-swig
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
LIBS = -lm
ARGS = SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)'

all::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' r_cpp

clean::
$(MAKE) -f $(TOP)/Makefile $(ARGS) r_clean
$(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' r_clean

check: all
R CMD BATCH runme.R
7 changes: 3 additions & 4 deletions Examples/r/simple/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ SWIG = $(TOP)/../preinst-swig
SRCS = example.c
TARGET = example
INTERFACE = example.i
ARGS = SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)'

all::
$(MAKE) -f $(TOP)/Makefile $(ARGS) r
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' r

clean::
$(MAKE) -f $(TOP)/Makefile $(ARGS) r_clean
$(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' r_clean

check: all
R CMD BATCH runme.R

0 comments on commit 314d4f1

Please sign in to comment.