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:
parent
ae8ac072da
commit
314d4f17de
4 changed files with 33 additions and 17 deletions
|
|
@ -56,28 +56,48 @@ example.c is the name of the file with the functions in them
|
|||
<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
|
||||
|
|
|
|||
|
|
@ -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* *~ .~*
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue