I just tried that procedure, and I get the following results when running the perl script after building:
perl runme.pl 
Can't load './example.bundle' for module example: dlopen(./example.bundle, 1): no suitable image found.  Did find:
./example.bundle: mach-o, but wrong architecture at /opt/local/lib/perl5/5.8.9/darwin-2level/DynaLoader.pm line 230.
 at example.pm line 11
Compilation failed in require at runme.pl line 4.
BEGIN failed--compilation aborted at runme.pl line 4.
On Dec 15, 2010, at 10:21 AM, Sri wrote:

Umm..I never had to look-into nor modify the Makefile.  I just followed the steps in the README and it just worked (configure, build and install swig, then compile and run the example).


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

This is the Makefile under swig-2.0.1/Examples/perl5/simple:
TOP        = ../..
SWIG       = $(TOP)/../preinst-swig
SRCS       = example.c
TARGET     = example
INTERFACE  = example.i
SWIGOPT    = 
all::
        $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
        SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5

I don't see anything that specifies the linking options there... perhaps that's what is supposed to be in SWIGOPT?

I also tried what I think was David's suggestion, and did the following:
swig -c++ -perl5 example.i
g++ -c example.cpp example_wrap.cxx `/usr/bin/perl -MExtUtils::Embed -e ccopts`
g++ `/usr/bin/perl -MExtUtils::Embed -e ccopts` -o example.dylib example.o example_wrap.o

I got a whole stack of errors as a result, starting with "Undefined symbols for architecture x86_64".

Any other suggestions?

Thanks,

Mike
On Dec 15, 2010, at 9:37 AM, Sri wrote:

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:

science.larc.nasa.gov/ceres/presentations/WrappingPerl.ppt

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
-------------------------------------------------------------------
/* 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
-------------------------------------------------------------------
//
//  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;} 
-------------------------------------------------------------------

example.i
-------------------------------------------------------------------
%include "exception.i"
%exception {

    try {
        $action
        } 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-1.0.0.0.dylib: Mach-O universal binary with 3 architectures
/System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level/lib/libsvn_swig_perl-1.0.0.0.dylib (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-1.0.0.0.dylib (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-1.0.0.0.dylib (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.
http://p.sf.net/sfu/lotusphere-d2d
_______________________________________________
Swig-user mailing list
Swig-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user