3

I am embeding perl interpreter in my C code (what fun!).

I need to dynamically load perl extensions (an extension that extends perl, written in C). When I run a perl script (using my embeded perl interpreter) that needs to use that extension, it will work!

starblue
  • 55,348
  • 14
  • 97
  • 151
Vertilka
  • 183
  • 2
  • 13
  • 2
    This question is not relevant to embedded programming, unless you are changing the perl interpreter to run on an embedded processor. See stackoverflow.com/questions/tagged/embedded – uɐɪ Oct 04 '10 at 08:13
  • I agree with Ian on the "embedded" tag. Thus, I removed it and instead added "perl-xs", which more clearly marks it as related to extending perl with C. – tsee Oct 04 '10 at 13:40
  • I disagree with this comment. embedding is not related only to embedded programming, but also in many programming areas as to "take an object from one environment and put/use in another". see following links: http://perldoc.perl.org/perlembed.html#Embedding-Perl-under-Win32, http://docs.python.org/release/2.5.2/ext/embedding.html, http://www.debian-administration.org/articles/264, and so on. the tag 'perl-xs' (extending) is related to this question but it is not the main issue that was asked. the main issue is: "when embedding the interpreter, how to do dynamic loading ?" – Vertilka Oct 06 '10 at 07:00

1 Answers1

6

Make sure to have pass an xs_init function to perl_parse that will provide DynaLoader::boot_DynaLoader for you. You can write those automatically with ExtUtils::Embed.

With that, all you need to do is, for example, eval some code that will load an extension written in C.

"Using Perl modules, which themselves use C libraries, from your C program" in perlembed explains this in detail.

rafl
  • 11,980
  • 2
  • 55
  • 77