Here is just one example of the commands when installing a CPAN module and using ExtUtils::MakeMaker:
/home/hermida/soft/perl/5.12.3/bin/perl /home/hermida/soft/perl/5.12.3
+/lib/5.12.3/ExtUtils/xsubpp -noprototypes -typemap /home/hermida/soft
+/perl/5.12.3/lib/5.12.3/ExtUtils/typemap -typemap typemap Expat.xs >
+ Expat.xsc && mv Expat.xsc Expat.c
gcc -c -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-p
+rotector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS
+=64 -O2 -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-prot
+ector --param=ssp-buffer-size=4 -m64 -mtune=native -march=native -g -
+DVERSION=\"2.40\" -DXS_VERSION=\"2.40\" -fPIC "-I/home/hermida/soft/p
+erl/5.12.3/lib/5.12.3/x86_64-linux-thread-multi/CORE" Expat.c
gcc -shared -O2 -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fsta
+ck-protector --param=ssp-buffer-size=4 -m64 -mtune=native -march=nati
+ve -g Expat.o -o ../blib/arch/auto/XML/Parser/Expat/Expat.so
This is how all CPAN Perl modules with C + XS code compile and link (yes some have some extra flags that are just relevant to that particular module, but the all have these as the basis). The first command is not necessary for SWIG as you already have the C code and as I showed before swig -perl example.i autogenerates XS and .pm and other wrapping C code automatically. Let's breakdown the above parts that ExtUtils::MakeMaker created for this command:
gcc -c [Config-ccflags] [Config-optimize] [Config-cccdlflags] "-I[Conf
+ig-archlib]/CORE" module.c
gcc [Config-lddlflags] module.o -o module.so
This creates everything you need to create the Perl module and has been tested successfully by me and by SWIG people just yesterday. We ran Perl code using the modules and they work perfectly.
Please tell me why this is wrong in detail.