Search code examples
perldynamicinterpreterembedded-language

How can I dynamically load perl extensions in an embeded perl interpreter?


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!


Solution

  • 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.