kingkongrevenge has asked for the wisdom of the Perl Monks concerning the following question:

I compile XS code to object code and link it in with my executable that has an embedded perl. The XS code call functions declared in the main executable; it's a callback module. The perl can't see my linked in module. When I "use Callback;" it dies looking for Callback.pm on the disk. If I make a Callback.pm and have it xsloader-bootstrap 'Callback' it dies looking for the .so. I have the proper boot functions in xs_init.

I'm quite lost. I got valid Callback.xs code that compiles fine to object code. I got "EXTERN_C void boot_Callback (pTHX_ CV* cv);" setup in the xs_init function, along with DynaLoader (which works fine). I got the perl in my main executable working fine and linking with my XS object code fine. But my Callback module DOESN'T WORK! Perl just keeps looking for stuff on the disk. How do I tell perl it doesn't need to do that?

This is all C++ using g++, if it matters.

Makefile: ... main : Callback.o ... $(CC) -o $@ $^ $(PERLLD) Callback.o : Callback.xs xsubpp Callback.xs > Callback.c $(CC) -c Callback.c $(PERLCXX)

Update: Got it working. All I had to do was add to the C++ code eval_pv("Callback::boot_Callback();", true);

Replies are listed 'Best First'.
Re: embedded perl using linked in XS modules
by ikegami (Patriarch) on Feb 11, 2009 at 03:57 UTC
    To continue on what the Anonymous Monk posted, if you're using use Callback; to import, you have two options.
    • Call import instead of use.

      Callback->VERSION(2.4); # use Callback 2.4; Callback->import(); # use Callback; Callback->import(qw( ... )); # use Callback qw( ... );
    • Tell Perl Callback is already loaded then use use as normal.

      my $mod = 'Callback'; $mod =~ s{::}{/}g; $INC{"$mod.pm"} = 1;

    Don't use <pre></pre>. Use <c>...</c> instead. And close your tags!

      None of this works. Perl simply does not see the linked in Callback.o. I am stuck.

      To be clear, the Callback.o was not linked into the original perl itself. I am linking it in with the default perl install by way of ExtUtils::Embed::ldopts.

        I misunderstood your question by accepting the anonymous monk's assumption that you had a problem locating a non-existent .pm. Our replies would only help if that was your problem.

        Anyway, this is way out of my field of experience. Without something (minimal!) I can play with, I can't fix your problem.

Re: embedded perl using linked in XS modules
by Anonymous Monk on Feb 11, 2009 at 03:40 UTC
    If you code is loaded, then there is no need to use Module;

    With over 20 posts under your belt you should know to use <code></code> tags.