Could not embed Perl in C
Hi, I was trying to embed Perl script in C and wrote the program as given. Then I tried to compile the program following program:
#include <EXTERN.h>
#include <perl.h>
static PerlInterpreter *my_perl;
int main(int argc, char **argv)
{
char* command_line[] = {"", "-e", "print \"Hello from C!\\n\";"};
my_perl = perl_alloc();
perl_construct(my_perl);
perl_parse(my_perl, NULL, 3, command_line, (char **)NULL);
perl_run(my_perl);
perl_destruct(my_perl);
perl_free(my_perl);
return 0;
}
I hope this program works fine, it was excerpted from the book "Extending and Embedding Perl".
First, I tried the following compilation:
$gcc -I /usr/lib/perl5/5.8.5/i386-linux-thread-multi/CORE
-L /usr/lib/perl5/5.8.5/i386-linux-thread-multi/CORE
-o test1 test1.c -lperl -lm
The program compiled and the binary was created. However, when i ran the binary, i got the following error message:
"error while loading shared libraries: libperl.so: cannot open shared object file: No such file or directory"
Now, i looked for the file libperl.so and found it in the folder /usr/lib/perl5/5.8.5/i386-linux-thread-multi/CORE. Do I need to link this file to some place else ? What am i doing wrong here ?
Another method for compilation was as follows:
$gcc -o test1.o -c test1.c 'perl -MExtUtils::Embed -e ccopts'
$gcc -o test1 test1.o 'perl -MExtUtils::Embed -e ldopts'
cc: perl -MExtUtils::Embed -e ccopts: No such file or directory
test1.c:1:20: EXTERN.h: No such file or directory
test1.c:2:18: perl.h: No such file or directory
yadayadayada
Please, I need some help regarding this, I have been trying this for a number of days, in vain. Thanks in advance.
|