LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-17-2009, 03:02 AM   #1
vinayashrestha
LQ Newbie
 
Registered: Feb 2009
Posts: 9

Rep: Reputation: 0
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.
 
Old 02-17-2009, 07:29 AM   #2
scoban
Member
 
Registered: Nov 2004
Location: Turkey
Distribution: Slackware
Posts: 145

Rep: Reputation: 16
Try to update LD_LIBRARY_PATH with "/usr/lib/perl5/5.8.5/i386-linux-thread-multi/CORE" path and try again.

Code:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/perl5/5.8.5/i386-linux-thread-multi/CORE
 
Old 02-18-2009, 02:19 AM   #3
vinayashrestha
LQ Newbie
 
Registered: Feb 2009
Posts: 9

Original Poster
Rep: Reputation: 0
Did not help

I tried that, but its the same as providing the path with -I option. This did not help me either.
 
Old 02-18-2009, 02:47 AM   #4
vinayashrestha
LQ Newbie
 
Registered: Feb 2009
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks man, it worked

setting LD_LIBRARY_PATH helped at the time i ran the binary. Thanks man.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Could not embed Perl in C vinayashrestha Programming 3 02-18-2009 11:43 PM
Embed X... okeyla Linux - Software 3 09-02-2005 03:34 PM
C/Perl embed : Libperl.so not found :( dicou Programming 0 04-19-2005 03:38 AM
embed perl into c walkinmud Programming 1 02-05-2004 02:13 AM
Module or embed? r_jensen11 Linux - Newbie 2 01-01-2004 05:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration