I dont have experience with Mac, but I normally match the build flags used in building the example provided in swig's source distribution.  If you can build that successfully, it may give you some clues.  I cant lookup the exact path now, but its something like  <your swig source root>/examples/perl5/

From: Michael Hearne <mhearne@usgs.gov>
To: swig-user@lists.sourceforge.net
Sent: Wed, December 15, 2010 9:51:29 PM
Subject: [Swig-user] Compiling Perl library on Mac OS 10.6

I'm having trouble compiling a Perl dynamic library on a Mac OS 10.6 laptop.  I found the following presentation on-line:


I used the example code found there to build a .dylib dynamic library.  When I try to run the example Perl script given there, I get the following error message:

Can't load './example.dylib' for module example: dlopen(./example.dylib, 1): no suitable image found.  Did find:
    ./example.dylib: mach-o, but wrong architecture at /System/Library/Perl/5.10.0/darwin-thread-multi-2level/DynaLoader.pm line 207.
at example.pm line 11
Compilation failed in require at ./TestExample.pl line 6.
BEGIN failed--compilation aborted at ./TestExample.pl line 6.

I've tried a couple of other examples of building Perl modules with SWIG, but none of them seem to work.  Does anyone have a recent example of building ANY simple Perl module using SWIG on Mac OS 10.6, with the correct linking commands included?

The details of my attempt are below:
/* Example.h */

#include <vector>
#include <string>

#define PGSd_EOS_AM        2222     
#define PGSd_EOS_PM        3333

double average(std::vector<int> v);

std::vector<double> half(const std::vector<double> & v);

std::string TestMod(const std::string &s);

//  example.cpp
#include <algorithm>
#include <functional>
#include <numeric>
#include "example.h"

using namespace std;

double average(vector<int> v) {  return (accumulate(v.begin(), v.end(), 0.0))/v.size();}

vector<double> half(const vector<double> & v) {
        vector<double> w(v);
        for( unsigned long i = 0; i < w.size(); i++)
                w[i] /= 2.0;
        return w; }

std::string TestMod(const std::string &s)  {return string("TestOutput: ") + s;}

%include "exception.i"
%exception {

    try {
        } catch (const std::exception &e) {
        SWIG_exception_fail(SWIG_RuntimeError, e.what());

%module example
/* Put headers and other declarations here */
#include "example.h"

%include "std_vector.i"
%include "std_string.i"

%template(IntVector) std::vector<int>;
%template(DoubleVector) std::vector<double>;
%include "example.h"

Build commands:
swig -c++ -perl5 example.i
g++ -c example.cpp example_wrap.cxx `/usr/bin/perl -MExtUtils::Embed -e ccopts`
g++ -dynamiclib  -single_module -flat_namespace -undefined suppress -o example.dylib example.o example_wrap.o

The results of `/usr/bin/perl -MExtUtils::Embed -e ccopts` are:
-arch x86_64 -arch i386 -arch ppc -g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -I/usr/local/include -I/System/Library/Perl/5.10.0/darwin-thread-multi-2level/CORE

The results of running "file example.dylib":
Mach-O 64-bit dynamically linked shared library x86_64

I looked at another .dylib file on my system and saw that it contained code for three architectures:
/System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level/lib/libsvn_swig_perl- Mach-O universal binary with 3 architectures
/System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level/lib/libsvn_swig_perl- (for architecture x86_64):    Mach-O 64-bit dynamically linked shared library x86_64
/System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level/lib/libsvn_swig_perl- (for architecture i386):    Mach-O dynamically linked shared library i386
/System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level/lib/libsvn_swig_perl- (for architecture ppc7400):    Mach-O dynamically linked shared library ppc
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
Swig-user mailing list