SwigPerl: .cxx compiler errors using %template's

A

Aaron

I am new to Swig and am having some real difficulties getting
this code to wrap properly. The problem here occurs when I insert
%template commands to manage the std::vectors in the C++ library. If I
don't insert these commands, then everything compiles fine. Any help
you can provide would be greatly appreciated.

First the colophon:
- FreeBSD 5.4-RELEASE
- GCC 3.4.2
- Swig 1.3.27
- Perl 5.8.7

Now the .i file:
--BEGIN .i FILE--
%module "Games::DungeonMaker"
%include "std_pair.i"
%include "std_vector.i"
%{
#include "DungeonMaker.h"
%}

%template (pair_ii) std::pair<int,int>;
%import "/usr/local/include/DungeonMaker.h";
%template (pair_cd) std::pair<CrawlerData, CrawlerData>;
%template (vector_ic) std::vector<IntCoordinate>;
%template (vector_dir) std::vector<Direction>;
%template (vector_rf) std::vector<RectFill>;
%template (vector_i) std::vector<int>;
%template (vector_cd) std::vector<CrawlerData>;
%template (vector_td) std::vector<TunnelerData>;
%template (vector_pair_cd) std::vector<std::pair<CrawlerData ,
CrawlerData> >;
%template (vector_ti) std::vector<TripleInt>;
%template (vector_square) std::vector<SquareData>;
%template (vector_room) std::vector<Room>;
%template (vector_flags) std::vector<FlagsDir>;

%include "/usr/local/include/DungeonMaker.h"
--END .i FILE--

I then run:
$ swig -c++ -perl -shadow DungeonMaker.i
with no errors. I then copy the resulting .cxx and .pm files to the
appropriate place and then compile the perl module as usual.

--BEGIN Makefile.PL--
WriteMakefile(
'NAME' => 'Games::DungeonMaker',
'VERSION_FROM' => 'lib/Games/DungeonMaker.pm', # finds
$VERSION
'PREREQ_PM' => {Test::More => 0.11},
'INC' => '-I/usr/local/include',
'LIBS' => ['-ldungeonmaker -lstdc++'],
'OBJECT' => 'DungeonMaker_wrap.o',
'CC' => 'g++',
($] >= 5.005 ?
(ABSTRACT_FROM => 'lib/Games/DungeonMaker.pm',
AUTHOR => 'Aaron Dalton <[email protected]>')
:
()),
);
--END Makefile.PL--

I then get a *slew* of compiler errors (see below). If I remove
the %template declarations for the vectors, then I do not get these
errors. I am very sorry to be such a bother, but I just don't know
what
is happening. I sincerely appreciate your time.

--BEGIN ERRORS--
g++ -c -I/usr/local/include
-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.7/BSDPAN" -DHAS_FPSETMASK
-DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe -I/usr/local/include
-O -pipe -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\" -DPIC -fPIC
"-I/usr/local/lib/perl5/5.8.7/mach/CORE" DungeonMaker_wrap.cxx
DungeonMaker_wrap.cxx: In function `int SWIG_Perl_ConvertPtr(SV*,
void**, swig_type_info*, int)':
DungeonMaker_wrap.cxx:727: warning: cast to pointer from integer of
different size
DungeonMaker_wrap.cxx: At global scope:
DungeonMaker_wrap.cxx:1109: error: `IntCoordinate' does not name a type
DungeonMaker_wrap.cxx:1116: error: expected init-declarator before '&'
token
DungeonMaker_wrap.cxx:1116: error: expected `,' or `;' before '&' token
DungeonMaker_wrap.cxx:1123: error: `IntCoordinate' was not declared in
this scope
DungeonMaker_wrap.cxx:1123: error: template argument 1 is invalid
DungeonMaker_wrap.cxx:1123: error: template argument 2 is invalid
DungeonMaker_wrap.cxx:1123: error: `IntCoordinate' has not been
declared
DungeonMaker_wrap.cxx:1123: error: ISO C++ forbids declaration of
`self' with no type
DungeonMaker_wrap.cxx:1123: error: ISO C++ forbids declaration of `x'
with no type
DungeonMaker_wrap.cxx: In function `void
std_vector_Sl_IntCoordinate_Sg__set(int*, int, int&)':
DungeonMaker_wrap.cxx:1124: error: expected primary-expression before
"int"
DungeonMaker_wrap.cxx:1124: error: expected `,' or `;' before "int"
DungeonMaker_wrap.cxx:1126: error: invalid types `int[int]' for array
subscript
DungeonMaker_wrap.cxx: At global scope:
DungeonMaker_wrap.cxx:1130: error: `Direction' does not name a type
DungeonMaker_wrap.cxx:1137: error: expected init-declarator before '&'
token
DungeonMaker_wrap.cxx:1137: error: expected `,' or `;' before '&' token
DungeonMaker_wrap.cxx:1144: error: `Direction' was not declared in this
scope
DungeonMaker_wrap.cxx:1144: error: template argument 1 is invalid
DungeonMaker_wrap.cxx:1144: error: template argument 2 is invalid
DungeonMaker_wrap.cxx:1144: error: `Direction' has not been declared
DungeonMaker_wrap.cxx:1144: error: ISO C++ forbids declaration of
`self' with no type
DungeonMaker_wrap.cxx:1144: error: ISO C++ forbids declaration of `x'
with no type
DungeonMaker_wrap.cxx: In function `void
std_vector_Sl_Direction_Sg__set(int*, int, int&)':
DungeonMaker_wrap.cxx:1145: error: expected primary-expression before
"int"
DungeonMaker_wrap.cxx:1145: error: expected `,' or `;' before "int"
DungeonMaker_wrap.cxx:1147: error: invalid types `int[int]' for array
subscript

etc, etc, etc......
--END ERRORS--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,246
Latest member
softprodigy

Latest Threads

Top