Fix running R examples and update docs about R CMD SHLIB

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12049 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2010-05-25 06:43:21 +00:00
commit 314d4f17de
4 changed files with 33 additions and 17 deletions

View file

@ -56,28 +56,48 @@ example.c is the name of the file with the functions in them
<div class="shell"> <div class="shell">
<pre> <pre>
swig -r example.i swig -r example.i
PKG_LIBS="example.c" R CMD SHLIB example_wrap.c R CMD SHLIB example_wrap.c example.c
</pre> </pre>
</div> </div>
<p> <p>
The corresponding comments for C++ mode are The corresponding options for C++ mode are
</p> </p>
<div class="shell"> <div class="shell">
<pre> <pre>
swig -c++ -r -o example_wrap.cpp example.i 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> </pre>
</div> </div>
<p> <p>
Note that R is sensitive to the name of the file and to the file Note that R is sensitive to the names of the files.
extension in C and C++ mode. The name of the wrapper file must be the The name of the wrapper file must be the
name of the library. Also in C++ mode, the file extension must be .cpp name of the library unless you use the -o option to R when building the library, for example:
rather than .cxx for the R compile command to recognize it.
</p> </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> <p>
The commands produces two files. A dynamic shared object file called 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 example.so, or example.dll, and an R wrapper file called example.R. To load these

View file

@ -1129,11 +1129,11 @@ RRSRC = $(INTERFACE:.i=.R)
r: $(SRCS) r: $(SRCS)
$(SWIG) -r $(SWIGOPT) $(INTERFACEPATH) $(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) r_cpp: $(CXXSRCS)
$(SWIG) -c++ -r $(SWIGOPT) -o $(RCXXSRCS) $(INTERFACEPATH) $(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: r_clean:
rm -f *_wrap* *~ .~* rm -f *_wrap* *~ .~*

View file

@ -3,16 +3,13 @@ SWIG = $(TOP)/../preinst-swig
CXXSRCS = example.cxx CXXSRCS = example.cxx
TARGET = example TARGET = example
INTERFACE = example.i INTERFACE = example.i
LIBS = -lm
ARGS = SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)'
all:: all::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' r_cpp TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' r_cpp
clean:: clean::
$(MAKE) -f $(TOP)/Makefile $(ARGS) r_clean $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' r_clean
check: all check: all
R CMD BATCH runme.R R CMD BATCH runme.R

View file

@ -3,14 +3,13 @@ SWIG = $(TOP)/../preinst-swig
SRCS = example.c SRCS = example.c
TARGET = example TARGET = example
INTERFACE = example.i INTERFACE = example.i
ARGS = SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)'
all:: all::
$(MAKE) -f $(TOP)/Makefile $(ARGS) r $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' r
clean:: clean::
$(MAKE) -f $(TOP)/Makefile $(ARGS) r_clean $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' r_clean
check: all check: all
R CMD BATCH runme.R R CMD BATCH runme.R