hermida has asked for the wisdom of the Perl Monks concerning the following question:
I submitted on the SWIG forums a request to update the Perl Module Building Tutorial for SWIG on their web site. The current tutorial doesn't even work when followed and the gcc compile and link commands appear to be incorrect when working with Perl. The current tutorial commands are:
First write or have your C code e.g. example.c then write the SWIG interface file for this code e.g. example.i. Then run the following:swig -perl5 example.i gcc -c example.c example_wrap.c `perl -MExtUtils::Embed -e ccopts` ld -G example.o example_wrap.o -o example.so
First thing I want to verify with everyone is that when you compile and link C/C++ code with XS that the compile and linking flags should be the same as those used to build Perl itself, is this correct? I believe so and the tutorial commands are not complete, actually they don't work as written.
I reviewed how CPAN modules with C code are regularly built during installation using ExtUtils::MakeMaker and they appear to always be at minimum like this:
So the new commands I proposed for SWIG are:gcc -c <ccflags> <optimize flags> <cccdlflags> "-I/path/to/perl/lib/CO +RE" module.c gcc <lddlflags> module.o -o module.so
Any thoughts? Could it be done better or differently? I looked at ExtUtils::Embed but it doesn't seem to havegcc -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 exampl +e_wrap.o -o example.so
Thanks to all the Perl monks on chatterbox for answering questions and telling me about Config.pm, Intrepid MidLifeXis and others...
|
|---|