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

Hi All,

I am new to Perl and experimenting static linking of modules in Perl. I have compiled a Perl without support for dynamic loading.

Normally I link any modules using xs_init call. Say If I were to load a module Filter::Util::Call, I will create a entry within xs_init function, which in turn is passed as argument to perl_parse.

xs_init(pTHX) { char *file = __FILE__; dXSUB_SYS; newXS("Filter::Util::Call::bootstrap", boot_Filter__Util__Call,file); }
PerlInterpreter *my_perl; #allocate memory for my_perl, construct my_perl, system initialization + ... perl_parse(my_perl, xs_init, argc, args, loc_environ);

Now I am trying to use DB_File module. Seems like DB_File depends on AUTOLOAD. Is there a way where can I statically load DB_File module as shown above. Or am I missing something about DB_File.

Replies are listed 'Best First'.
Re: Static linking of DB_File
by Anonymous Monk on Jun 07, 2011 at 01:30 UTC
    s there a way where can I statically load DB_File module as shown above. Or am I missing something about DB_File.

    I think this is how you're supposed to do it

    cd DB_File perl Makefile.PL make perl make inst_perl
    now your static perl comes with DB_File

    Repeat for every module with XS components

      I tried above commands. But I am encountering few errors

      cd GDBM_File perl Makefile.PL make perl
      gcc -c -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -DVERSION=\"1.14\" -DXS_VERSION=\"1.14\" "-I../.." GDBM_File.c GDBM_File.xs:7:18: error: gdbm.h: No such file or directory GDBM_File.xs:16: error: expected specifier-qualifier-list before \u2018GDBM_FILE\u2019 GDBM_File.xs:22: error: expected \u2018=\u2019, \u2018,\u2019, \u2018;\u2019, \u2018asm\u2019 or \u2018__attribute__\u2019 before \u2018datum_key\u2019 GDBM_File.xs:23: error: expected \u2018=\u2019, \u2018,\u2019, \u2018;\u2019, \u2018asm\u2019 or \u2018__attribute__\u2019 before \u2018datum_value\u2019 GDBM_File.xs:24: error: expected \u2018=\u2019, \u2018,\u2019, \u2018;\u2019, \u2018asm\u2019 or \u2018__attribute__\u2019 before \u2018datum_key_copy\u2019 ./const-xs.inc: In function \u2018XS_GDBM_File_AUTOLOAD\u2019: ./const-xs.inc:137: warning: format \u2018%d\u2019 expects type \u2018int\u2019, but argument 4 has type \u2018line_t\u2019 ./const-xs.inc:142: warning: format \u2018%d\u2019 expects type \u2018int\u2019, but argument 4 has type \u2018line_t\u2019 GDBM_File.xs: In function \u2018XS_GDBM_File_TIEHASH\u2019:

      DB_File, GDBM_File, SDBM_File, ODBM_File and NDBM_File are core perl modules. But I noticed that only SDBM_File being installed. So I am trying to install rest of the modules manually. Any help is really appreciated

        But I am encountering few errors

        Listen to the error message :)

        GDBM_File.xs:7:18: error: gdbm.h: No such file or directory GDBM_File.xs:16

        http://cpansearch.perl.org/src/JESSE/perl-5.14.1/ext/GDBM_File/Makefile.PL

        LIBS => ["-lgdbm", "-ldbm"]

        GDBM_File is the perl interface to libgdbm, which you need to have installed if you wish to install GDBM_File

        DB_File, GDBM_File, SDBM_File, ODBM_File and NDBM_File are core perl modules. But I noticed that only SDBM_File being installed. So I am trying to install rest of the modules manually. Any help is really appreciated

        See AnyDBM_File, it explains, SDBM comes with perl (i'm sure other docs like READMEs explain this also), the rest are provided by the operating-system. You don't need all of them :)