Update examples to talk about a version of Perl which we actually still

support.
Use $ for the shell prompt character, since that matches what most users
will see.
Compile code for shared use with -fPIC, since that's required for most
architectures, and a good idea even on x86.
Fix Sun C++ example to use CC not g++ for invoking the compiler.
Drop space before colon in prose. 


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12959 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Olly Betts 2012-03-27 04:18:36 +00:00
commit 7d6da8d319

View file

@ -149,19 +149,19 @@ In order to compile, SWIG extensions need the following Perl5 header files :</p>
These are typically located in a directory like this</p> These are typically located in a directory like this</p>
<div class="code"><pre> <div class="code"><pre>
/usr/lib/perl5/5.00503/i386-linux/CORE /usr/lib/perl/5.14/CORE
</pre></div> </pre></div>
<p> <p>
The SWIG configuration script automatically tries to locate this directory so The SWIG configuration script automatically tries to locate this directory so
that it can compile examples. However, if you need to find out where the directory is that it can compile examples. However, if you need to find out where the directory is
loaded, an easy way to find out is to run Perl itself. located, an easy way to find out is to ask Perl itself:
</p> </p>
<div class="code"> <div class="code">
<pre> <pre>
% perl -e 'use Config; print $Config{archlib};' $ perl -e 'use Config; print "$Config{archlib}\n";'
/usr/lib/perl5/5.00503/i386-linux /usr/lib/perl/5.14
</pre> </pre>
</div> </div>
@ -176,9 +176,9 @@ using commands like this (shown for Linux):
<div class="code"><pre> <div class="code"><pre>
$ swig -perl example.i $ swig -perl example.i
% gcc example.c $ gcc -fPIC example.c
% gcc -c example_wrap.c -I/usr/lib/perl5/5.00503/i386-linux/CORE -Dbool=char $ gcc -fPIC -c example_wrap.c -I/usr/lib/perl/5.14/CORE -Dbool=char
% gcc -shared example.o example_wrap.o -o example.so $ gcc -shared example.o example_wrap.o -o example.so
</pre></div> </pre></div>
<p> <p>
@ -221,9 +221,9 @@ WriteMakefile(
Now, to build a module, simply follow these steps:</p> Now, to build a module, simply follow these steps:</p>
<div class="code"><pre> <div class="code"><pre>
% perl Makefile.PL $ perl Makefile.PL
% make $ make
% make install $ make install
</pre></div> </pre></div>
<p> <p>
@ -242,7 +242,7 @@ interpreter with your SWIG extensions added to it. To build a static
extension, you first need to invoke SWIG as follows:</p> extension, you first need to invoke SWIG as follows:</p>
<div class="code"><pre> <div class="code"><pre>
% swig -perl -static example.i $ swig -perl -static example.i
</pre></div> </pre></div>
<p> <p>
@ -271,7 +271,7 @@ extern int fact(int);
The same thing can be accomplished by running SWIG as follows:</p> The same thing can be accomplished by running SWIG as follows:</p>
<div class="code"><pre> <div class="code"><pre>
% swig -perl -static -lperlmain.i example.i $ swig -perl -static -lperlmain.i example.i
</pre></div> </pre></div>
<p> <p>
@ -290,7 +290,7 @@ for a dynamic module, but change the link line to something like this:
</p> </p>
<div class="code"><pre> <div class="code"><pre>
% gcc example.o example_wrap.o -L/usr/lib/perl5/5.00503/i386-linux/CORE \ $ gcc example.o example_wrap.o -L/usr/lib/perl/5.14/CORE \
-lperl -lsocket -lnsl -lm -o myperl -lperl -lsocket -lnsl -lm -o myperl
</pre></div> </pre></div>
@ -323,9 +323,7 @@ A common error received by first-time users is the following:
<div class="targetlang"> <div class="targetlang">
<pre> <pre>
use example; use example;
Can't locate example.pm in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-lin Can't locate example.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at - line 1.
ux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/pe
rl5/site_perl/5.005 .) at - line 1.
BEGIN failed--compilation aborted at - line 1. BEGIN failed--compilation aborted at - line 1.
</pre> </pre>
</div> </div>
@ -363,7 +361,7 @@ Another common error is the following:
<pre> <pre>
use example; use example;
Can't load './example.so' for module example: ./example.so: Can't load './example.so' for module example: ./example.so:
undefined symbol: Foo at /usr/lib/perl5/5.00503/i386-linux/DynaLoader.pm line 169. undefined symbol: Foo at /usr/lib/perl/5.14/i386-linux/DynaLoader.pm line 169.
at - line 1 at - line 1
BEGIN failed--compilation aborted at - line 1. BEGIN failed--compilation aborted at - line 1.
@ -409,7 +407,7 @@ error when you try to use your module:
<pre> <pre>
use example; use example;
Can't load './example.so' for module example: libfoo.so: cannot open shared object file: Can't load './example.so' for module example: libfoo.so: cannot open shared object file:
No such file or directory at /usr/lib/perl5/5.00503/i386-linux/DynaLoader.pm line 169. No such file or directory at /usr/lib/perl/5.14/i386-linux/DynaLoader.pm line 169.
at - line 1 at - line 1
BEGIN failed--compilation aborted at - line 1. BEGIN failed--compilation aborted at - line 1.
@ -472,10 +470,10 @@ compiler. For example:
</p> </p>
<div class="code"><pre> <div class="code"><pre>
% swig -c++ -perl example.i $ swig -c++ -perl example.i
% g++ -c example.cxx $ g++ -fPIC -c example.cxx
% g++ -c example_wrap.cxx -I/usr/lib/perl5/5.00503/i386-linux/CORE $ g++ -fPIC -c example_wrap.cxx -I/usr/lib/perl/5.14/i386-linux/CORE
% <b>g++ -shared example.o example_wrap.o -o example.so</b> $ <b>g++ -shared example.o example_wrap.o -o example.so</b>
</pre></div> </pre></div>
<p> <p>
@ -485,10 +483,10 @@ Solaris, you often need to add an extra library <tt>-lCrun</tt> like this:
</p> </p>
<div class="code"><pre> <div class="code"><pre>
% swig -c++ -perl example.i $ swig -c++ -perl example.i
% g++ -c example.cxx $ CC -c example.cxx
% g++ -c example_wrap.cxx -I/usr/lib/perl5/5.00503/i386-linux/CORE $ CC -c example_wrap.cxx -I/usr/lib/perl/5.14/i386-linux/CORE
% g++ -shared example.o example_wrap.o -o example.so <b>-lCrun</b> $ CC -shared example.o example_wrap.o -o example.so <b>-lCrun</b>
</pre></div> </pre></div>
<p> <p>
@ -503,7 +501,7 @@ it needs to be. So you should compile the wrapper like:
</p> </p>
<div class="code"><pre> <div class="code"><pre>
% g++ -c example_wrap.cxx -I/usr/lib/perl/5.8.0/CORE -D_GNU_SOURCE $ g++ -fPIC -c example_wrap.cxx -I/usr/lib/perl/5.8.0/CORE -D_GNU_SOURCE
</pre></div> </pre></div>
<p> <p>
@ -511,7 +509,7 @@ it needs to be. So you should compile the wrapper like:
</p> </p>
<div class="code"><pre> <div class="code"><pre>
% perl -e 'use Config; print $Config{ccflags};' $ perl -e 'use Config; print "$Config{ccflags}\n";'
</pre></div> </pre></div>
<p> <p>
@ -519,8 +517,8 @@ So you could also compile the wrapper like
</p> </p>
<div class="code"><pre> <div class="code"><pre>
% g++ -c example_wrap.cxx -I/usr/lib/perl/5.8.0/CORE \ $ g++ -fPIC -c example_wrap.cxx -I/usr/lib/perl/5.8.0/CORE \
`perl -e 'use Config; print $Config{ccflags}'` `perl -MConfig -e 'print $Config{ccflags}'`
</pre></div> </pre></div>
<p> <p>
@ -568,7 +566,7 @@ can behave strangely when working with multiple modules.
<p> <p>
It should be noted that you may get a lot of error messages It should be noted that you may get a lot of error messages
about the `<tt>bool</tt>' datatype when compiling a C++ Perl module. If about the '<tt>bool</tt>' datatype when compiling a C++ Perl module. If
you experience this problem, you can try the following:</p> you experience this problem, you can try the following:</p>
<ul> <ul>
@ -1276,7 +1274,7 @@ a single Perl module. The name of the module is determined by the
</p> </p>
<div class="targetlang"><pre> <div class="targetlang"><pre>
% perl5 $ perl5
use example; # load the example module use example; # load the example module
print example::fact(4),"\n" # Call a function in it print example::fact(4),"\n" # Call a function in it
24 24
@ -1346,7 +1344,7 @@ option :
</p> </p>
<div class="code"><pre> <div class="code"><pre>
% swig -perl -package Foo example.i $ swig -perl -package Foo example.i
</pre></div> </pre></div>
<p> <p>