On second glance, you did not dlsym'ed boot_DynaLoader() that's why xs_init() had trouble.

This is a complete, compilable and runnable example:

/* author: bliako date: 05/05/2020 for: https://perlmonks.org/?node_id=11116476 compile with: $(perl -MConfig -e 'print $Config{cc}') a.c $(perl -MExtUtils::Embed - +e ccopts -e ldopts) -o aaa -ldl run with: ./aaa -e 'print "hello there, I am a tiny wee Perl!!\n"' */ #include <EXTERN.h> #include <perl.h> #include "XSUB.h" #include <dlfcn.h> // void boot_DynaLoader (pTHX_ CV* cv); /* this declares a function pointer as opposed to an external function + above */ void (*boot_DynaLoader)(pTHX_ CV* cv); void xs_init(pTHX) { static const char file[] = __FILE__; dXSUB_SYS; PERL_UNUSED_CONTEXT; newXS( "DynaLoader::boot_DynaLoader", boot_DynaLoader, file ); } static PerlInterpreter *my_perl; int main( int argc, char **argv, char **env ) { /* find path to shared library */ /* open shared lib */ void *handle = dlopen("/usr/lib64/libperl.so.5.28.2", RTLD_NOW); /* Get entry point for perl_alloc */ void* (*perl_alloc)(); perl_alloc = (void *(*)() )dlsym(handle, "perl_alloc"); /* Get all the functions you will be using from the library, t +his one is obvious */ boot_DynaLoader = (void (*)(pTHX_ CV* cv) )dlsym(handle, "boot_Dyn +aLoader"); /* Call perl_alloc */ my_perl = perl_alloc(); /* and so on */ perl_construct(my_perl); perl_parse( my_perl, xs_init, argc, argv, env ); int result = perl_run(my_perl); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); return result; }

Edit: added a typecast to boot_DynaLoader = (void (*)(pTHX_ CV* cv) )dlsym(handle, "boot_DynaLoader");

bw, bliako


In reply to Re: How to setup the DynaLoader in a dynamically loaded perl? by bliako
in thread How to setup the DynaLoader in a dynamically loaded perl? by sciurius

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.