=?UTF-8?B?U2FsdmFkb3IgRmFuZGnDsW8=?= <[EMAIL PROTECTED]> writes:
>> It isn't too hard to have/write a tiny C++ file and "try" the c++ command
>> you find.
>>
>> open(my $fh,">test.cpp") || die;
>> print $fh <<'END';
>> #include <iostream>
>> int main(int argc,char *argv[])
>> {
>> std::cout << "It works\n";
>> return 0;
>> }
>> END
>> close($fh);
>> if (system($cpp_to_try,"test.cpp") == 0)
>> {
>> # that will do
>> }
>
>but testing that a C++ program compiles is not enough, i.e., gcc
>(the command) would pass this test and still create unusable
>modules because of the missing stdc++ lib.
We are not building a module at this point, it is an executable.
The above will either produce 'a.out' (or test.exe) or fail to link.
It is not too much harder to
my $name = 'test'.$Config{exe_ext};
if (system($cpp_to_try,-o => $name, "test.cpp") == 0)
{
my $line = `$name`;
if ($? == 0 && defined($line) && $line eq '"It works\n")
{
# it ran as well
}
}
"We" could do with some Configure-oid modules to do this kind of thing.
Here is the C version that Tk uses (for library probing), it isn't bomb proof
but it does what I need.
(From Tk804.025/Tk/MMtry.pm)
my $stderr_too = ($^O eq 'MSWin32') ? '' : '2>&1';
sub try_run
{
my ($file,$inc,$lib) = @_;
$inc = [] unless $inc;
$lib = [] unless $lib;
my $out = basename($file,'.c').$Config{'exe_ext'};
warn "Test Compile/Run $file\n";
my $msgs = `$Config{'cc'} -o $out $Config{'ccflags'} @$inc $file @$lib $stderr_too`;
my $ok = ($? == 0);
# warn "$Config{'cc'} -o $out $Config{'ccflags'} @$inc $file @$lib:\n$msgs" if $msgs;
if ($ok)
{
my $path = File::Spec->rel2abs($out);
$msgs = `$path $stderr_too`;
$ok = ($? == 0);
# warn "$path:$msgs" if $msgs;
}
unlink($out) if (-f $out);
return $ok;
}
>
>The only reliable solution would be to include a C++ test module
>and try to build and check it with different configurations until
>one succeeds.
Certainly an option - perl has a XS test extension, we could
add a C++ test extension to MakeMaker - it does not have to be huge
after all!
>
>
>Bye,
>
> - Salva