Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Makefile.pl for a C++ XS module... How to make windows happy?

by JayBonci (Curate)
on Feb 27, 2004 at 10:26 UTC ( [id://332223]=perlquestion: print w/replies, xml ) Need Help??

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

Hey there everyone. I have a perl module up on CPAN right now, that is an XS module written in C++. It works great for me and anyone of the Unixy persuasion (save cygwin for some reason). My problem is, I don't know how to tell ExtUtils::MakeMaker to simply use "any c++ compiler". Right now it's hardcoded to use g++, but I know that kills win32 users of the module. (There's also a CPAN tester failure saying as much).

The module is here, IP::Unique. The Makefile.PL script is:
use 5.005; use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. my $mod = my $pm = "IP::Unique"; $pm =~ s/::/\//g; $pm = "lib/$pm.pm"; + unless(-e "CHANGES") { open CHANGES,">>CHANGES"; print CHANGES "Temp CHANGES file\n"; close CHANGES; } my $CC = "g++"; WriteMakefile( NAME => $mod, VERSION_FROM => $pm, # finds $VERSION PREREQ_PM => {}, # e.g., Module::Name => 1.1 ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => $pm, # retrieve abstract from module AUTHOR => 'Jay Bonci <jaybonci@cpan.org>') : ()), CC => $CC, CCFLAGS => "-Wall", LD => '$(CC)', LIBS => [''], # e.g., '-lm' DEFINE => '', # e.g., '-DHAVE_SOMETHING' INC => '-I.', XSOPT => '-C++', OBJECT => '$(O_FILES)', # link all the C files too 'dist' => { #Auto-generate the CHANGES file PREOP => "podselect $pm -section CHANGES | pod2text -w 1000 -i + 5 | perl -pe \"s/^\s+(Version.*)/\$1/g;\" > CHANGES", }, );
Basically, I wish XSOPTS was smarter, or 'CC' was a smarter variable. Is there an Win32 or general $ENV thing I can pull for this, or is there a good c++ xs module that would serve as an example. Thanks.


    --jaybonci

Replies are listed 'Best First'.
Re: Makefile.pl for a C++ XS module... How to make windows happy?
by Corion (Patriarch) on Feb 27, 2004 at 10:36 UTC

    I don't have a Linux box handy, but Config.pm tells me that $Config{cpp} would be "the" C++ compiler to use:

    Q:\>perl -MConfig -e die$Config{cpp} cl -nologo -E at -e line 1.
    and on Solaris :
    perl -MConfig -edie\$Config{cpp} cpp at -e line 1.

    (for the Sun delivered perl 5.005_03)

      Great, that's what I needed to know. Thanks =)


          --jaybonci
      > Config.pm tells me that $Config{cpp} would be "the" C++ compiler to use:

      Wrong, most wrong. $Config{cpp} is the C preprocessor. There is no Config.pm variable for a C++ compiler.

      In most places you can just use $Config{cc}, though. The compilers are the same, really, or at least the frontend recognizes from the source code filenames (use .cpp for C++) which backend to use.

Re: Makefile.pl for a C++ XS module... How to make windows happy?
by PodMaster (Abbot) on Feb 27, 2004 at 10:51 UTC
      Other than that fprintf and the other C constructs are so much more useful and terse than the C++ streams, what is the reason for not "crossing the streams" (Sorry for bad Ghostbuster's analogy) with C++ and Perl on win32?
        Because it simply won't compile, no other reason. It's like trying to compile a perlXS extension (like Storable) with perl 5.005_03 (one of the first win32 versions) -- it requres significant modification of the perl core :(

        I hope some future perl5 version will support this, but I wouldn't depend on it (maybe it will be supported through cross-compiling, MinGW anyone? :D)

        MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
        I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
        ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Makefile.pl for a C++ XS module... How to make windows happy?
by ambrus (Abbot) on Feb 27, 2004 at 18:53 UTC

    To compile c++ programs on linux boxes, you can use gcc too. From the extension of the sources, gcc will find out that it's in c++, and compile them as such. All you need is to pass gcc the parameter -lstdc++ when linking.

    You could try doing this on the linux box, and then it may be easier to port this solution to windows. I'm not quite sure.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-03-28 16:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found