Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

perl in C >>> "dynamic loading not available in this perl."

by jithoosin (Scribe)
on Dec 16, 2005 at 05:19 UTC ( [id://517143]=perlquestion: print w/replies, xml ) Need Help??

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

Hi monks,
I am calling a perl subroutine from a C file and the perl file uses "USE DBI". When i executed the C file i got the error
dynamic loading not available in this perl. (You may need to build a new perl executable which either supports dynamic loading or has the Socket module statically linked into it.)
Then i went through "Using Perl modules, which themselves use C libraries, from your C program" in perlembed to read about the error. The perl subroutine which i call from C file call many other perl modules . Could some one help me on this matter.These were the sequence of command i tried out to correct the error
perl -MExtUtils::Embed -e xsinit -- -o perlxsi.c % cc -c perlxsi.c `perl -MExtUtils::Embed -e ccopts` % cc -c interp.c `perl -MExtUtils::Embed -e ccopts` % cc -o interp perlxsi.o interp.o `perl -MExtUtils::Embed -e ldopts`
But even after these kind of compilation the error remained the same. Could some one help me in this matter (interp.c is the name of my C file)

Replies are listed 'Best First'.
Re: perl in C >>> "dynamic loading not available in this perl."
by Courage (Parson) on Dec 16, 2005 at 07:57 UTC
    following excerpt from perldoc perlembed is for you:
    Using Perl modules, which themselves use C libraries, from your C pr +ogram If you've played with the examples above and tried to embed a scri +pt that *use()*s a Perl module (such as *Socket*) which itself uses a + C or C++ library, this probably happened: Can't load module Socket, dynamic loading not available in this p +erl. (You may need to build a new perl executable which either suppor +ts dynamic loading or has the Socket module statically linked into +it.) What's wrong? Your interpreter doesn't know how to communicate with these extens +ions on its own. A little glue will help. Up until now you've been call +ing *perl_parse()*, handing it NULL for the second argument: perl_parse(my_perl, NULL, argc, my_argv, NULL); That's where the glue code can be inserted to create the initial c +ontact between Perl and linked C/C++ routines. Let's take a look some pie +ces of *perlmain.c* to see how Perl does this: static void xs_init (pTHX); EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);

    Best regards,
    Courage, the Cowardly Dog

Re: perl in C >>> "dynamic loading not available in this perl."
by chromatic (Archbishop) on Dec 16, 2005 at 07:38 UTC

    If you run perl -V, do you see anything for "Dynamic Linking"? If not, you'll probably have to rebuild Perl.

Re: perl in C >>> "dynamic loading not available in this perl."
by Anonymous Monk on Jan 13, 2006 at 06:13 UTC
    Sorry,I also encounted this question and I used the way which Courage had offered. But,I still can't pass my program and the question still remained. Could anyone answer the question? 3Q.
      If the error is the same, you need to try again. The only way is to recompile perl with support for dynamic loading.

        I got it.

        Last friday,I passed my program.Now I will share my solution.

        1---->perl_parse(my_perl, NULL, argc, my_argv, NULL); 2----> perl -MExtUtils::Embed -e xsinit -- -o perlxsi.c cc -c perlxsi.c `perl -MExtUtils::Embed -e ccopts`

        Then perlxsi.c document has created.The file is:

        --------------------------------

        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); }

        ------------------------------

        That's where the glue code can be inserted to create the initial contact between Perl and linked C/C++ routines. Let's take a look some pieces of perlmain.c to see how Perl does this:

        Once you have this code, slap it into the second argument of perl_parse():

        3----->perl_parse(my_perl, xs_init, argc, my_argv, NULL); and the file interp.c must include "perlxsi.c"; 4-----> cc -o interp interp.c `perl -MExtUtils::Embed -e ccopts -e ldo +pts` interp

        I wish it could help somebody.

        If you want to connect with me ,this is my email:

        shengzongxian@gmail.com

        Edited by planetscape - added code tags

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://517143]
Approved by spiritway
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-12-08 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (50 votes). Check out past polls.