Hi, 

I am trying to call Perl from C. I hit a problem when I try to load dynamic 
librarires.  I have taken the following code from the PerlEmbed documentation 
(http://www.perldoc.com/perl5.8.4/pod/perlembed.html) but cannot get it to compile.

This seems to be widely used stuff, so it sholdnt be this hard to get it to work!!

Here are the contents of my c file:
--------------------------------------------------------------------------------------------------------------------------------------
#include <EXTERN.h>
#include <perl.h>


 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__;

        dXSUB_SYS; /* I have also added this line as I have seen it in many examples. 
I dont know what it does but it doesnt affect the error message */

        /* DynaLoader is a special case */
        newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
        newXS("Socket::bootstrap", boot_Socket, file);
 }  


static PerlInterpreter *my_perl;

int main(int argc, char **argv, char **env)
{
        char *my_argv[] = { "", "sxiconn.pl" };  

        my_perl = perl_alloc();
        perl_construct(my_perl);


        printf ("Loading Perl <sxiconn.pl> file...\n") ;
        perl_parse(my_perl, xs_init, argc, my_argv, NULL); 
        printf ("Loaded Perl file.\n") ;

        perl_destruct(my_perl);
        perl_free(my_perl);
}  



I compile with:
--------------------------------------------------------------------------------------------------------------------------------------
gcc -O2 -R /usr/local/lib/perl5/5.8.4/sun4-solaris/CORE -L/usr/local/lib 
-I/usr/local/lib/perl5/5.8.4/sun4-solaris/CORE 
-L/usr/local/lib/perl5/5.8.4/sun4-solaris/CORE  
/usr/local/lib/perl5/5.8.4/sun4-solaris/auto/DynaLoader/DynaLoader.a 
-I/usr/local/include -o temp temp.c -lperl -lsocket -lnsl -ldl -lm -lc > gccoutput 2>&1


The error message is as follows:
--------------------------------------------------------------------------------------------------------------------------------------
Undefined                       first referenced
 symbol                             in file
boot_DynaLoader                     /var/tmp//ccbgVfzA.o
boot_Socket                         /var/tmp//ccbgVfzA.o
ld: fatal: Symbol referencing errors. No output written to temp
collect2: ld returned 1 exit status



Any suggestions would be greatly appreciated!

Many thanks, 
Paul
mailto:[EMAIL PROTECTED]


Reply via email to