develooper Front page | perl.perl5.porters | Postings from January 2004

Re: Embeding Perl problem with boot_DynaLoader

Thread Previous | Thread Next
From:
Nick Ing-Simmons
Date:
January 6, 2004 04:20
Subject:
Re: Embeding Perl problem with boot_DynaLoader
Message ID:
20040106122029.4021.9@llama.elixent.com
Unkno Me <pembed2003@yahoo.com> writes:
>Hi all, This is my first post in this list. I am writing a C application where
>I am embeding a Perl interpreter and use it to execute Perl code. The C file
>is then compiled to generate a .so file where another application will load
>the .so library. I use the following steps to generate the .so file:
>
>cc `perl -MExtUtils::Embed -e ccopts` -c perlembed.c cc -shared -rdynamic
>`perl -MExtUtils::Embed -e ldopts` -o perlembed.so perlembed.o
>
>this will generate a perlembed.so file and is later used by another
>application. Everything works fine so far. Inside perlembed.c, I have a line
>that reads:
>
>perl_parse(my_perl,NULL,2,nothing,NULL);
>
>this creates a Perl interpreter that does not understand dynamic loading of
>other Perl module written in C so I figure I should fix that by doing:
>
>perl -MExtUtils::Embed -e xsinit
>
>which generate a perlxsi.c. I then take the content of this file and slap
>(copy and paste) at the beginning of the perlembed.c file and change the
>above line to:
>
>perl_parse(my_perl,xs_init,2,nothing,NULL);
>
>I then compile and link again to generate a new .so file. The compilation and
>linkage generates no error but whenever I tried to load the .so file, the
>following error popup:
>
>undefined symbol: boot_DynaLoader in xxx.c on line xxx
>
>It looks like it's not able to find the function. I checked perlembed but
>still couldn't figure out what went wrong. Does anyone have any idea? What am
>I missing?

Solaris and Linux use (roughly) the the same dynamic loading model.
Description bellow applies there, and probably other places that 
use "modern" version of dlopen(). [It does NOT apply to Sunos4...]


When you load a .so file it can see symbols in the executable, but 
not (by default) in the things executable has loaded.
So: 
  if you load Foo.so into 'perl' it finds boot_DynaLoader in 'perl'

But if 'bar' loads perlembed.so and that loads 'Foo.so' then Foo.so 
looks in 'bar' which hasn't got a boot_DynaLoader.

You can fix this by having 'bar' load perlembed.so 
using the RTLD_GLOBAL flag:
   dlopen(".../perlembed.so",RTLD_GLOBAL)

this adds it to list of places Foo.so will look.

This is probably more a <perl-xs@perl.org> type question... 



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About