Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

How to make an XS module with a different C compiler?

by mifflin (Curate)
on Jan 18, 2005 at 00:46 UTC ( [id://422855]=perlquestion: print w/replies, xml ) Need Help??

mifflin has asked for the wisdom of the Perl Monks concerning the following question:

I have an XS module that I now need to use a the Sun Studio 8 compiler. How do I make xs use it?

My Makefile.PL looks like...
use ExtUtils::MakeMaker; $acelib = '/opt/Ace750cRev1/postware/acelib'; WriteMakefile( 'NAME' => 'ACE', 'VERSION_FROM' => 'ACE.pm', 'LIBS' => ["-L$acelib -lace"], 'DEFINE' => '-DSolaris64', 'INC' => "-I$acelib", );
Building the Makefile...
erickn@isfe:/home/erickn/ACE> perl Makefile.PL Checking if your kit is complete... Looks good Writing Makefile for ACE
Making the extention...
erickn@isfe:/home/erickn/ACE> make cp ace_constants.pl blib/lib/ace_constants.pl cp ACE.pm blib/lib/ACE.pm /home/utils/perl/bin/perl /home/utils/perl/lib/perl5/5.8.0/ExtUtils/xs +ubpp -typemap /home/utils/perl/lib/perl5/5.8.0/ExtUtils/typemap -typ +emap typemap ACE.xs > ACE.xsc && mv ACE.xsc ACE.c gcc -c -I/opt/Ace750cRev1/postware/acelib -I/home/utils/perl/include + -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O -DVERSION=\"3.00\" + -DXS_VERSION=\"3.00\" -fPIC "-I/home/utils/perl/lib/perl5/5.8.0/sun4 +-solaris/CORE" -DSolaris64 ACE.c Running Mkbootstrap for ACE () chmod 644 ACE.bs rm -f blib/arch/auto/ACE/ACE.so LD_RUN_PATH="/opt/Ace750cRev1/postware/acelib" gcc -G -L/home/utils/p +erl/lib ACE.o -o blib/arch/auto/ACE/ACE.so -L/opt/Ace750cRev1/post +ware/acelib -lace chmod 755 blib/arch/auto/ACE/ACE.so cp ACE.bs blib/arch/auto/ACE/ACE.bs chmod 644 blib/arch/auto/ACE/ACE.bs Manifying blib/man3/ACE.3
As you can see it still uses gcc. However I want it to use the new Studio 8 compiler.
Both are available in my path...
erickn@isfe:/home/erickn/ACE> type gcc gcc is /usr/local/bin/gcc erickn@isfe:/home/erickn/ACE> type cc cc is a tracked alias for /usr/local/studio8/SUNWspro/bin/cc
And my $PATH is...
erickn@isfe:/home/erickn/ACE> echo $PATH /usr/local/studio8/SUNWspro/bin:/home/erickn/bin:/home/utils/perl/bin: +/home/utils/perl/scripts:/v0/oracle/bin:/usr/bin:/usr/dt/bin:/usr/ope +nwin/bin:/usr/ccs/bin:/usr/sbin:/usr/ucb:/usr/bin/nsr:/usr/sbin/nsr:/ +usr/local/bin:/usr/local/scripts:/usr/local/mistools:/usr/lib:/opt/op +enssh/bin:/opt/SUNWppro/bin:/usr/annex/bin/SUN/:/opt/vsifax/bin:/usr/ +local/SUNWexplo/bin:/usr/opt/SUNWmd/sbin:/opt/imagemagick/bin:.:/usr/ +local/oracle:/home/oramwh/scripts/forms_drivers:/prod/share/bin:/prod +/dbadmin/util/bin
So, my questions are...
1. Why is it by default using gcc in /usr/local/bin ?
2. How do I make it use cc in /usr/local/studio8/SUNWspro/bin ?

Replies are listed 'Best First'.
Re: How to make an XS module with a different C compiler?
by Fletch (Bishop) on Jan 18, 2005 at 00:52 UTC

    The Makefile that ExtUtils::MakeMaker creates (and probably Module::Build as well, although I'm less familiar with it) uses whatever the Config module's $Config{cc} says use. This is whatever compiler was used to build your perl executable. You can probably override it with make CC=/usr/local/.../cc on the command line, but keep in mind that there's probably a whole can of monkeys hiding underneath waiting to bite you in the tuckus if the compilers don't play nice together (different link expectations, expecting different symbols to be defined in something like crt0.o, yadda yadda yadda).

      Regarding the monkeys, I haven't played with this much but I'm wondering: if this is true, should it not also be true that one can only safely compile XS modules using the same compiler and settings that Perl itself was built with on one's machine?

        It's not that you have to use the same compiler, it's just more likely that you're going to have problems if you don't. Just be sure to have bribes handy for your local C guru and/or sysadmin to get them to lay hands on things when they break.

      So, are you telling me that if I have two vendors that I get libraries from and both will only give me the .so files and each choose to use a different compilier to build their product that I would not be able to use one installation of Perl to access them because I would have to choose one of those compiliers to build my Perl?

        Maybe yes, maybe no. It all depends on the OS, the compiler used, the phase of the moon. You may get lucky and figure out what flags are causing cc to choke (-fpic is a gcc-ism for instance that's causing problems in your output below).

        It's even worse with C++ though (there's no standard for name mangling, for example, so two different compilers can make completely different symbols in the output object for the same int foo( char *bar, double& baz ).

      I tried your suggestion and I do get lots of errors.
      Are these the types of errors that will "bite me in the tukas" ?
      erickn@isfe:/home/erickn/ACE> perl Makefile.PL Checking if your kit is complete... Looks good Writing Makefile for ACE erickn@isfe:/home/erickn/ACE> make CC=/usr/local/studio8/SUNWspro/bin/ +cc cp ACE.pm blib/lib/ACE.pm /home/utils/perl/bin/perl /home/utils/perl/lib/perl5/5.8.0/ExtUtils/xs +ubpp -typemap /home/utils/perl/lib/perl5/5.8.0/ExtUtils/typemap -typ +emap typemap ACE.xs > ACE.xsc && mv ACE.xsc ACE.c /usr/local/studio8/SUNWspro/bin/cc -c -I/opt/Ace750cRev1/postware/ace +lib -I/home/utils/perl/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BI +TS=64 -O -DVERSION=\"3.00\" -DXS_VERSION=\"3.00\" -fPIC "-I/home/ +utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE" -DSolaris64 ACE.c cc: Warning: illegal option -fPIC "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/perlio.h", line 20 +9: syntax error before or at: __attribute__ "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/perlio.h", line 20 +9: warning: old-style declaration or incorrect type for: __attribute_ +_ "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/perlio.h", line 20 +9: warning: syntax error: empty declaration "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/perlio.h", line 26 +9: syntax error before or at: __attribute__ "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/perlio.h", line 26 +9: warning: old-style declaration or incorrect type for: __attribute_ +_ "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/perlio.h", line 26 +9: identifier redefined: __attribute__ current : function() returning int previous: function() returning int : "/home/utils/perl/lib/per +l5/5.8.0/sun4-solaris/CORE/perlio.h", line 209 "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/perlio.h", line 26 +9: warning: syntax error: empty declaration "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/perlio.h", line 27 +3: syntax error before or at: __attribute__ "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/perlio.h", line 27 +3: warning: old-style declaration or incorrect type for: __attribute_ +_ "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/perlio.h", line 27 +3: identifier redefined: __attribute__ current : function() returning int previous: function() returning int : "/home/utils/perl/lib/per +l5/5.8.0/sun4-solaris/CORE/perlio.h", line 269 "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/perlio.h", line 27 +3: warning: syntax error: empty declaration "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/proto.h", line 98: + syntax error before or at: __attribute__ "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/proto.h", line 98: + warning: old-style declaration or incorrect type for: __attribute__ "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/proto.h", line 98: + identifier redefined: __attribute__ current : function() returning int previous: function() returning int : "/home/utils/perl/lib/per +l5/5.8.0/sun4-solaris/CORE/perlio.h", line 273 "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/proto.h", line 102 +: warning: syntax error: empty declaration "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/proto.h", line 103 +: syntax error before or at: __attribute__ "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/proto.h", line 103 +: warning: old-style declaration or incorrect type for: __attribute__ "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/proto.h", line 103 +: identifier redefined: __attribute__ current : function() returning int previous: function() returning int : "/home/utils/perl/lib/per +l5/5.8.0/sun4-solaris/CORE/proto.h", line 98 "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/proto.h", line 103 +: warning: syntax error: empty declaration "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/proto.h", line 503 +: syntax error before or at: __attribute__ "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/proto.h", line 503 +: warning: old-style declaration or incorrect type for: __attribute__ "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/proto.h", line 503 +: identifier redefined: __attribute__ current : function() returning int previous: function() returning int : "/home/utils/perl/lib/per +l5/5.8.0/sun4-solaris/CORE/proto.h", line 103 "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/proto.h", line 503 +: warning: syntax error: empty declaration "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/proto.h", line 504 +: syntax error before or at: __attribute__ "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/proto.h", line 504 +: warning: old-style declaration or incorrect type for: __attribute__ "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/proto.h", line 504 +: identifier redefined: __attribute__ current : function() returning int previous: function() returning int : "/home/utils/perl/lib/per +l5/5.8.0/sun4-solaris/CORE/proto.h", line 503 "/home/utils/perl/lib/perl5/5.8.0/sun4-solaris/CORE/proto.h", line 504 +: warning: syntax error: empty declaration cc: acomp failed for ACE.c *** Error code 2 make: Fatal error: Command failed for target `ACE.o'
Re: How to make an XS module with a different C compiler?
by gellyfish (Monsignor) on Jan 18, 2005 at 09:44 UTC

    If your Perl was built with gcc then you almost certainly want to use gcc to compile the extension, the dynamic libraries (.so files) should work anyway but there will be a strong chance the different compilers will have different symbols and use a different C Runtime library - this can cause problems when building extensions even with different versions of the same compiler (see for example http://www.mail-archive.com/perl5-porters@perl.org/msg84195.html. I would recommend trying to get this work with gcc (does make test give any errors?) and only then attempt to use a different compiler.

    /J\

      Do you see any gotchas if I decided to rebuild my current Perl installtion with the Sun Studio 8 compiler?

      Would I then have problems adding other XS modules like DBI, DBD::Oracle, XML::Parser ...?

        In general no, I think you should be alright using the Sun compiler. If you have a number of modules already installed you might want to run cpan autobundle before you trash your old Perl.

        /J\

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://422855]
Approved by Fletch
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 21:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found