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?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re: Plz suggest what is the problem in the following code? by BrowserUk
in thread Plz suggest what is the problem in the following code? by sanjay nayak

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.