From: William S F. <ws...@fu...> - 2011-03-25 20:03:05
|
Thanks for suggestions. I've updated the tutorial as suggested. Please check it and confirm it is correct. I don't get those warnings though with latest SWIG. William On 25/03/11 13:31, Leandro Hermida wrote: > Hello everyone, > > Ok so the Perl Module Building tutorial might need to be updated. My > first question is, in Perl when you compile and link and C code to use > via XS you need to use the same compiling and linking flags that were > used to build Perl itself. Why with the SWIG Perl module building are > we not doing the same? You will find that in CPAN any modules that you > install with XS C/C++ code always do their compile and link commands > like this: > > gcc -c <ccflags> <optimize flags> <cccdlflags> module.c > gcc <lddlflags> module.o -o module.so > > I've left out certain options that aren't important for SWIG. The > cccdlflags have -fPIC. > > In order to get all of the flags above that were used to build Perl the > module ExtUtils::Embed doesn't have all of these so we need to use the > Perl core Config.pm module that comes with Perl and gives you access to > all original Perl configuration information. > > So I believe the Perl compiling and linking SWIG tutorial commands after > the swig -perl example.i command should now be: > > gcc -c `perl -MConfig -e 'print join(" ", @Config{qw(ccflags optimize > cccdlflags)}, "-I$Config{archlib}/CORE")'` example.c example_wrap.c > gcc `perl -MConfig -e 'print @Config{qw(lddlflags)}'` example.o > example_wrap.o -o example.so > > The lddlflags already has the -G/-shared option for the second linking > command so we don't need that. > > I've tested the tutorial with these new commands and it works perfectly, > after the compile command you only get these normal warnings now: > > example_wrap.c: In function ‘SWIG_Perl_ConvertPtr’: > example_wrap.c:1101: warning: value computed is not used > example_wrap.c: In function ‘SWIG_Perl_MakePtr’: > example_wrap.c:1123: warning: value computed is not used > example_wrap.c: In function ‘boot_example’: > example_wrap.c:1974: warning: unused variable ‘items’ > > What do you guys think? > > best, > Leandro > > > On Thu, Mar 24, 2011 at 8:23 AM, <man...@be... > <mailto:man...@be...>> wrote: > > I used to have the same problem. > Try this: > gcc -fPIC -c swig_example.c swig_example_wrap.c `perl > -MExtUtils::Embed -e ccopts` > > ------------------------------------------------------------------------ > *Von:* Leandro Hermida [mailto:so...@le... > <mailto:so...@le...>] > *Gesendet:* Mittwoch, 23. März 2011 19:03 > *An:* swi...@li... > <mailto:swi...@li...> > *Betreff:* [Swig-user] SWIG Tutorial doesn't work for building Perl > module example > > Hi, > > When running through the SWIG tutorial on the web site when I get to > the Perl module build step I get the following error: > > % ld -G swig_example.o swig_example.o -o swig_example.so > > /usr/bin/ld: swig_example.o: relocation R_X86_64_32 against `a local > symbol' can not be used when making a shared object; recompile with > -fPIC > swig_example.o: could not read symbols: Bad value > collect2: ld returned 1 exit status > > Am I doing something wrong or is the tutorial out-of-date? > > > > > ------------------------------------------------------------------------------ > Enable your software for Intel(R) Active Management Technology to meet the > growing manageability and security demands of your customers. Businesses > are taking advantage of Intel(R) vPro (TM) technology - will your software > be a part of the solution? Download the Intel(R) Manageability Checker > today! http://p.sf.net/sfu/intel-dev2devmar > > > > _______________________________________________ > Swig-user mailing list > Swi...@li... > https://lists.sourceforge.net/lists/listinfo/swig-user |