Monks, thank you very much. Someone send me this very good link on calling perl from C/C++. Thank you very much for the same. The link is here

Am though getting one last problem, when am compiling (actually during linking) my program is not able to find out the correct library. is there anything missing?

# gcc -g -o test_socket test_socket.c `perl -MExtUtils::Embed -e cc +opts -e ldopts` /tmp/ccgdPXUT.o(.text+0x34): In function `xs_init': test_socket.c:19: undefined reference to `boot_Socket' collect2: ld returned 1 exit status test_socket.c ============= #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; static void xs_init (pTHX); EXTERN_C void boot_DynaLoader (pTHX_ CV* cv); EXTERN_C void boot_Socket (pTHX_ CV* cv); EXTERN_C void xs_init(pTHX) { char *file = __FILE__; /* DynaLoader is a special case */ newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); newXS("Socket::bootstrap", boot_Socket, file); } int main(int argc, char **argv, char **env) { PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; perl_parse(my_perl, xs_init, argc, argv, (char **)NULL); call_argv("mymethod", G_DISCARD , args); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); } mysocket.pl =========== #!/usr/local/bin/perl use Socket; sub mymethod() { @arr=gethostbyname('localhost'); print "@arr \n"; } running procedure ================= as per the material this binary has to be run like #./test_socket mysocket.pl

In reply to calling perl from C/C++ by perl_fan

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.