Dear monks I am facing an issue with embedding a perl interpreter in my C program.
First let me explain what I try to achieved. A C program (commercial sendxms) calls a callback function within a shared lib.
I want to be able to use Perl there so I figured out how to embed a perl interpreter in my share lib.
Everything is fine, except that Dynaloader doesn’t do its job correctly when I compile as a shared lib.
(everything works fine as a stand alone)

here is the Error:

2004.02.01, 11:10:01.437996, [Libertel_O2_055] connected: 212.155.169. +123

I am Userexit for cause 98 and client Libertel_O2_055
trying to incarn perl

Can't load '/usr/local/lib/perl5/site_perl/5.8.0/i686-linux/auto/IPC/S +hareLite/ShareLite.so' for module IPC::ShareLite: /usr/local/lib/perl +5/site_perl/5.8.0/i686-linux/auto/IPC/ShareLite/ShareLite.so: undefin +ed symbol: PL_sv_undef at /usr/local/lib/perl5/5.8.0/i686-linux/DynaL +oader.pm line 229. at sevexit.pl line 7 Compilation failed in require at sevexit.pl line 7.
Sevexit.pl : package MOBILEWAY::sevexit; #sevexit.pl print "heelo\n"; sub test { my @prra = @_; use IPC::ShareLite; print "hello there my pid is $$\n"; my $i=0; foreach my $param(@prra) { $i++; print "Param $i = $param\n"; } close FILE; return ("test"); } 1;
Here is the sharelib itself :
the xs glue /* sevexit.c */ #include <EXTERN.h> #include <perl.h> EXTERN_C void xs_init (pTHX); EXTERN_C void boot_DynaLoader (pTHX_ CV* cv); EXTERN_C void xs_init(pTHX) { char *file = __FILE__; dXSUB_SYS; /* DynaLoader is a special case */ newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); }
The compilation line I use
cc -shared -o sevexit.o sevexit.c `perl -MExtUtils::Embed -e ccopts -e + ldopts`
and `perl -MExtUtils::Embed -e ccopts -e ldopts` is
-rdynamic -L/usr/local/lib /usr/local/lib/perl5/5.8.0/i686-linux/auto +/DynaLoader/DynaLoader.a -L/usr/local/lib/perl5/5.8.0/i686-linux/CORE + -lperl -lnsl -ldl -lm -lc -lcrypt -lutil -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE +_OFFSET_BITS=64 -I/usr/local/lib/perl5/5.8.0/i686-linux/CORE
I do have perl compile as a sharelib (I have liperl.so).
As I said everything works fine as long as I don’t try to build a sharelib.
I read somewhere that the problem could be that Dynaloader.a is not compiled using –fPIC?

Here is my perl –V

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuratio +n: Platform: osname=linux, osvers=2.4.18-64gb-smp, archname=i686-linux uname='linux steroide1 2.4.18-64gb-smp #1 smp wed mar 27 13:58:12 +utc 2002 i686 unknown ' config_args='-de' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultipl +icity=undef useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LA +RGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O3', cppflags='-fno-strict-aliasing -I/usr/local/include' ccversion='', gccversion='2.95.3 20010315 (SuSE)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1 +2 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', + lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -ldl -lm -lc -lcrypt -lutil perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil libc=, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.2.5' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynami +c' cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib' Characteristics of this binary (from libperl): Compile-time options: USE_LARGE_FILES Built under linux Compiled at Jul 26 2003 20:50:03 @INC: /usr/local/lib/perl5/5.8.0/i686-linux /usr/local/lib/perl5/5.8.0 /usr/local/lib/perl5/site_perl/5.8.0/i686-linux /usr/local/lib/perl5/site_perl/5.8.0 /usr/local/lib/perl5/site_perl

I am really pulling my hears !! I you have any idea or direction I could look at that would be greatly appreciated.
Thanks a lot
Severan

Edited by BazB removed excessive whitespace, deal with square brackets, fix typo in title.


In reply to Embed and shared lib by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.