/* 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 #include #include "XSUB.h" #include // 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, this one is obvious */ boot_DynaLoader = (void (*)(pTHX_ CV* cv) )dlsym(handle, "boot_DynaLoader"); /* 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; }