in reply to Plz suggest what is the problem in the following code?
Use of inherited AUTOLOAD for non-method main::main() is deprecated at inline1.p l line 10.Can't locate auto/main/main.al in @INC (@INC contains: E:\sanjayweb\_Inline\lib C:/Perl/site/lib C:/Perl/lib .) at inline1.pl line 10
You should also be seeing an error message:
Warning. No Inline C functions bound to Perl Check your C function definition(s) for Inline compatibility
Which is trying to tell that although there are no C errors from your C code, the functions it contains weren't able to be 'bound' (made available) to your Perl code.
In the case of your main() function, this is because it is not possible to pass a pointer to an array of pointers to chars (char *argv[] from Perl to C, because there is no way to construct one in Perl. That means you could never call your main() function safely from Perl, so there is no point in binding it.
As the function has not been bound, when you attempt to call it, it cannot be found, so Perl falls back to its default behaviour and attempts to autoload it. And as nothing in your program provided an autoloadable main() function, that fails. Hence the error message you posted.
Basically, there are a limited number of C types that can be automatically "typemapped" from Perl to C, and char *argv[] is not one of them.
If you change the function definition to only use mappable types, then the function will then be bound. For example:
#!C:\Perl\bin\perl.exe -w #Inline1.pl use Inline ( C => 'DATA' ); main(); __DATA__ __C__ int main( int argc, char *argv ) { printf( "%d - %s\n", argc, argv ); return; }
will compile and link cleanly, but will fail at runtime with:
Usage: main::main(argc, argv) at c:\test\junk7.pl line 7.
because you aren't passing the parameters.
Correct that:
#!C:\Perl\bin\perl.exe -w #Inline1.pl use Inline ( C => 'DATA' ); main( 3, 'fred' ); __DATA__ __C__ int main( int argc, char *argv ) { printf( "%d - %s\n", argc, argv ); return; }
and you'll be rewarded with
c:\test>junk7 3 - fred
There is no conflict with having an Inline::C routine called main(). There's just no point to it because it will not act as a C main routine, and will not be passed the arguments from the command line in the normal C style manner. If you wanted to pass the arguments given to your perl script directly through to your C function, then you would need something like:
#!C:\Perl\bin\perl.exe -w #Inline1.pl use Inline ( C => 'DATA' ); main( scalar @ARGV, \@ARGV ); __DATA__ __C__ int main( int argc, AV *argv ) { int i; for( i=0; i< argc; i++ ) { printf( "%s\n", SvPVX( *av_fetch( argv, i, NULL ) ) ); } return 0; }
Which when run might produce:
c:\test>junk7 1 fred bill 3.2 1 fred bill 3.2
But it's unclear what the point of doing that would be?
|
|---|