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?


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."

Replies are listed 'Best First'.
Re^2: Plz suggest what is the problem in the following code?
by derby (Abbot) on Feb 03, 2009 at 22:25 UTC

    Hmmm ... this is either an OS issue or a compiler issue. On my up-to-date ubuntu boxes, your examples segfault. I chalked it up to the two mains issue (which if not a cross-platform bug is at least bad form). I can see where dynamic loading after the interpreter could let you load a shared object that has another main defined (and from what I can tell, Inline does no type of name mangling) so ... maybe that behavior is undefined?

    -derby

      What does the .xs file look like for the final example? Mine looks like this:

      #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "INLINE.h" 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; } MODULE = junk7_pl_b750 PACKAGE = main PROTOTYPES: DISABLE int main (argc, argv) int argc AV * argv

      I can't see anything there that is platform, or compiler dependant?


      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.

        Exactly the same (below). Now at compile time, I cannot link two objects that have main defined - I get a "multiple definition of 'main'" error .. but when I try to dynamically load a shared object that has another main defined, no problem. Hmmm ... may be a problem with my install of perl or Inline ....

        #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "INLINE.h" 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; } MODULE = test_pl_bcca PACKAGE = main PROTOTYPES: DISABLE int main (argc, argv) int argc AV * argv
        -derby
Re^2: Plz suggest what is the problem in the following code?
by Anonymous Monk on Feb 04, 2009 at 06:42 UTC

    Hello BrowserUk

    Many many thanks for your reply.

    Now that code is working fine. But actually i have downloaded a open source c project named pjproject-1.0.1. <href>http://www.pjsip.org/download.htm</href>. I have compiled and run it successfully in my Visual studio C++.

    Now i want to use it in my perl program.

    The code is as follows


    when i want to run it in perl. I am getting error as follows.

    But the same code is working fine if i run it by using Visual studio C++.

    Plz suggest what is the problem with it? It shows some linking errors.

    i think it is due to some linking problem. I have set path to all includes and libraies to that pjproject. Still i am getting error. Plz suggest what is the problem with it? Is there any specific way to set path to includes and lib of any project.

    Regd's
    Sanjay
Re^2: Plz suggest what is the problem in the following code?
by sanjay nayak (Sexton) on Feb 04, 2009 at 06:52 UTC

    Hello BrowserUk

    Many many thanks for your reply.

    Now that code is working fine. But actually i have downloaded a open source c project named pjproject-1.0.1. http://www.pjsip.org/download.htm. I have compiled and run it successfully in my Visual studio C++.

    Now i want to use it in my perl program.

    The code is as follows
    #!C:\Perl\bin\perl.exe -w #Inline.pl no AutoLoader; use Inline ( C => 'DATA', INC => ' -IE:\pjproject-1.0.1\pjsip\include -IE:\pjproject-1.0.1\pjli +b\include -IE:\pjproject-1.0.1\pjlib-util\include -IE:\pjproject-1.0. +1\pjnath\include -IE:\pjproject-1.0.1\pjmedia\include', LIBS => '-LE:\pjproject-1.0.1\pjsip\lib -lpjsip-core-i386-win32-vc6-de +bug.lib -LE:\pjproject-1.0.1\pjsip\lib -lpjsip-simple-i386-win32-vc6- +debug.lib -LE:\pjproject-1.0.1\pjsip\lib -lpjsip-ua-i386-win32-vc6-de +bug.lib -LE:\pjproject-1.0.1\pjsip\lib -lpjsua-lib-i386-win32-vc6-deb +ug.lib -LE:\pjproject-1.0.1\pjlib\lib -lpjlib-i386-win32-vc6-debug.li +b -LE:\pjproject-1.0.1\pjlib\lib -lpjlib-i386-win32-vc6-debug.lib -LE +:\pjproject-1.0.1\pjlib-util\lib -lpjlib-util-i386-win32-vc6-debug.li +b -LE:\pjproject-1.0.1\pjnath\lib -lpjnath-i386-win32-vc6-debug.lib - +LE:\pjproject-1.0.1\pjmedia\lib -lpjmedia-codec-i386-win32-vc6-debug. +lib -LE:\pjproject-1.0.1\pjmedia\lib -lpjmedia-i386-win32-vc6-debug.l +ib'); @ARGV = ('www.abc.com'); main(scalar @ARGV, \@ARGV ); __DATA__ __C__ #define PJ_WIN32 1; #include <pjlib.h> #include <pjlib-util.h> #include <pjnath.h> #include <pjsip.h> #include <pjsip_ua.h> #include <pjsip_simple.h> #include <pjsua-lib/pjsua.h> #include <pjmedia.h> #include <pjmedia-codec.h> #include <pjsua-lib/pjsua.h> #define THIS_FILE "APP" #define SIP_DOMAIN "acti.com" #define SIP_USER "sanjay" #define SIP_PASSWD "sanjay" //start //end /* Callback called by the library upon receiving incoming call */ static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_i +d, pjsip_rx_data *rdata) { pjsua_call_info ci; PJ_UNUSED_ARG(acc_id); PJ_UNUSED_ARG(rdata); pjsua_call_get_info(call_id, &ci); PJ_LOG(3,(THIS_FILE, "Incoming call from %.*s!!", (int)ci.remote_info.slen, ci.remote_info.ptr)); /* Automatically answer incoming calls with 200/OK */ pjsua_call_answer(call_id, 200, NULL, NULL); } /* Callback called by the library when call's state has changed */ static void on_call_state(pjsua_call_id call_id, pjsip_event *e) { pjsua_call_info ci; PJ_UNUSED_ARG(e); pjsua_call_get_info(call_id, &ci); PJ_LOG(3,(THIS_FILE, "Call %d state=%.*s", call_id, (int)ci.state_text.slen, ci.state_text.ptr)); } /* Callback called by the library when call's media state has changed +*/ static void on_call_media_state(pjsua_call_id call_id) { pjsua_call_info ci; pjsua_call_get_info(call_id, &ci); if (ci.media_status == PJSUA_CALL_MEDIA_ACTIVE) { // When media is active, connect call to sound device. pjsua_conf_connect(ci.conf_slot, 0); pjsua_conf_connect(0, ci.conf_slot); } } /* Display error and exit application */ static void error_exit(const char *title, pj_status_t status) { pjsua_perror(THIS_FILE, title, status); pjsua_destroy(); exit(1); } /* * main() * * argv[1] may contain URL to call. */ /* //int main(int argc, char *argv[]) the previous code //the perl specific code int main(int argc, AV *argv) { pjsua_acc_id acc_id; pj_status_t status; // Create pjsua first! status = pjsua_create(); if (status != PJ_SUCCESS) error_exit("Error in pjsua_create()", st +atus); // If argument is specified, it's got to be a valid SIP URL if (argc > 1) { status = pjsua_verify_sip_url(argv[1]); if (status != PJ_SUCCESS) error_exit("Invalid URL in argv", status +); } // Init pjsua { pjsua_config cfg; pjsua_logging_config log_cfg; pjsua_config_default(&cfg); cfg.cb.on_incoming_call = &on_incoming_call; cfg.cb.on_call_media_state = &on_call_media_state; cfg.cb.on_call_state = &on_call_state; pjsua_logging_config_default(&log_cfg); log_cfg.console_level = 4; status = pjsua_init(&cfg, &log_cfg, NULL); if (status != PJ_SUCCESS) error_exit("Error in pjsua_init()", stat +us); } // Add UDP transport. { pjsua_transport_config cfg; pjsua_transport_config_default(&cfg); cfg.port = 5060; status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL); if (status != PJ_SUCCESS) error_exit("Error creating transport", s +tatus); } // Initialization is done, now start pjsua status = pjsua_start(); if (status != PJ_SUCCESS) error_exit("Error starting pjsua", statu +s); // Register to SIP server by creating SIP account. { pjsua_acc_config cfg; pjsua_acc_config_default(&cfg); cfg.id = pj_str("sip:" SIP_USER "@" SIP_DOMAIN); cfg.reg_uri = pj_str("sip:" SIP_DOMAIN); cfg.cred_count = 1; cfg.cred_info[0].realm = pj_str(acti.com); cfg.cred_info[0].scheme = pj_str("digest"); cfg.cred_info[0].username = pj_str(sanjay); cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD; cfg.cred_info[0].data = pj_str(sanjay); status = pjsua_acc_add(&cfg, PJ_TRUE, &acc_id); if (status != PJ_SUCCESS) error_exit("Error adding account", statu +s); } // If URL is specified, make call to the URL. if (argc > 1) { pj_str_t uri = pj_str(argv[1]); status = pjsua_call_make_call(acc_id, &uri, 0, NULL, NULL, NULL); if (status != PJ_SUCCESS) error_exit("Error making call", status); } // Wait until user press "q" to quit. for (;;) { char option[10]; puts("Press 'h' to hangup all calls, 'q' to quit"); fgets(option, sizeof(option), stdin); if (option[0] == 'q') break; if (option[0] == 'h') pjsua_call_hangup_all(); } // Destroy pjsua pjsua_destroy(); return 0; }

    when i want to run it in perl. I am getting error as follows.

    But the same code is working fine if i run it by using Visual studio C++.

    Plz suggest what is the problem with it? It shows some linking errors.

    i think it is due to some linking problem. I have set path to all includes and libraies to that pjproject. Still i am getting error. Plz suggest what is the problem with it? Is there any specific way to set path to includes and lib of any project.

    Regd's
    Sanjay

      Before you will be able to make this work, you will need to contact your local MS representative and ask them to supply you with a Complex Language Understanding Experience.

      It is simply impossible until you get one.