perl_fan has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: calling perl from C/C++
by Anonymous Monk on Dec 24, 2008 at 17:03 UTC
    You write call_argv("mysocket", G_DISCARD , args); and your file is mysocket.pl, two differents(like perlfan is not perl_fan).
Re: calling perl from C/C++
by Anonymous Monk on Dec 24, 2008 at 16:57 UTC
    perl MExtUtils::Embed -e ccopts -e ldopts Can't open perl script "MExtUtils::Embed": No such file or directory
    Its -MMODULE::NAME
      sorry, you are correct. But the problem is same. (updated the command in the original message)
        And you're still not showing output from command, the important part.