{
    "mode": "perldoc",
    "parameter": "DynaLoader",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/DynaLoader/json",
    "generated": "2026-06-15T13:08:55Z",
    "synopsis": "package YourPackage;\nrequire DynaLoader;\n@ISA = qw(... DynaLoader ...);\nPACKAGE->bootstrap;\n# optional method for 'global' loading\nsub dlloadflags { 0x01 }",
    "sections": {
        "NAME": {
            "content": "DynaLoader - Dynamically load C libraries into Perl code\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "package YourPackage;\nrequire DynaLoader;\n@ISA = qw(... DynaLoader ...);\nPACKAGE->bootstrap;\n\n# optional method for 'global' loading\nsub dlloadflags { 0x01 }\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This document defines a standard generic interface to the dynamic linking mechanisms available\non many platforms. Its primary purpose is to implement automatic dynamic loading of Perl\nmodules.\n\nThis document serves as both a specification for anyone wishing to implement the DynaLoader for\na new platform and as a guide for anyone wishing to use the DynaLoader directly in an\napplication.\n\nThe DynaLoader is designed to be a very simple high-level interface that is sufficiently general\nto cover the requirements of SunOS, HP-UX, Linux, VMS and other platforms.\n\nIt is also hoped that the interface will cover the needs of OS/2, NT etc and also allow\npseudo-dynamic linking (using \"ld -A\" at runtime).\n\nIt must be stressed that the DynaLoader, by itself, is practically useless for accessing\nnon-Perl libraries because it provides almost no Perl-to-C 'glue'. There is, for example, no\nmechanism for calling a C library function or supplying arguments. A C::DynaLib module is\navailable from CPAN sites which performs that function for some common system types. And since\nthe year 2000, there's also Inline::C, a module that allows you to write Perl subroutines in C.\nAlso available from your local CPAN site.\n\nDynaLoader Interface Summary\n\n@dllibrarypath\n@dlresolveusing\n@dlrequiresymbols\n$dldebug\n$dldlext\n@dllibrefs\n@dlmodules\n@dlsharedobjects\nImplemented in:\nbootstrap($modulename)                               Perl\n@filepaths = dlfindfile(@names)                     Perl\n$flags = $modulename->dlloadflags                  Perl\n$symref  = dlfindsymbolanywhere($symbol)          Perl\n\n$libref  = dlloadfile($filename, $flags)           C\n$status  = dlunloadfile($libref)                   C\n$symref  = dlfindsymbol($libref, $symbol)          C\n@symbols = dlundefsymbols()                        C\ndlinstallxsub($name, $symref [, $filename])        C\n$message = dlerror                                  C\n\n@dllibrarypath\nThe standard/default list of directories in which dlfindfile() will search for libraries\netc. Directories are searched in order: $dllibrarypath[0], [1], ... etc\n\n@dllibrarypath is initialised to hold the list of 'normal' directories (/usr/lib, etc)\ndetermined by Configure ($Config{'libpth'}). This should ensure portability across a wide\nrange of platforms.\n\n@dllibrarypath should also be initialised with any other directories that can be\ndetermined from the environment at runtime (such as LDLIBRARYPATH for SunOS).\n\nAfter initialisation @dllibrarypath can be manipulated by an application using push and\nunshift before calling dlfindfile(). Unshift can be used to add directories to the front of\nthe search order either to save search time or to override libraries with the same name in\nthe 'normal' directories.\n\nThe load function that dlloadfile() calls may require an absolute pathname. The\ndlfindfile() function and @dllibrarypath can be used to search for and return the\nabsolute pathname for the library/object that you wish to load.\n\n@dlresolveusing\nA list of additional libraries or other shared objects which can be used to resolve any\nundefined symbols that might be generated by a later call to loadfile().\n\nThis is only required on some platforms which do not handle dependent libraries\nautomatically. For example the Socket Perl extension library (auto/Socket/Socket.so)\ncontains references to many socket functions which need to be resolved when it's loaded.\nMost platforms will automatically know where to find the 'dependent' library (e.g.,\n/usr/lib/libsocket.so). A few platforms need to be told the location of the dependent\nlibrary explicitly. Use @dlresolveusing for this.\n\nExample usage:\n\n@dlresolveusing = dlfindfile('-lsocket');\n\n@dlrequiresymbols\nA list of one or more symbol names that are in the library/object file to be dynamically\nloaded. This is only required on some platforms.\n\n@dllibrefs\nAn array of the handles returned by successful calls to dlloadfile(), made by bootstrap,\nin the order in which they were loaded. Can be used with dlfindsymbol() to look for a\nsymbol in any of the loaded files.\n\n@dlmodules\nAn array of module (package) names that have been bootstrap'ed.\n\n@dlsharedobjects\nAn array of file names for the shared objects that were loaded.\n",
            "subsections": [
                {
                    "name": "dl_error",
                    "content": "Syntax:\n\n$message = dlerror();\n\nError message text from the last failed DynaLoader function. Note that, similar to errno in\nunix, a successful function call does not reset this message.\n\nImplementations should detect the error as soon as it occurs in any of the other functions\nand save the corresponding message for later retrieval. This will avoid problems on some\nplatforms (such as SunOS) where the error message is very temporary (e.g., dlerror()).\n\n$dldebug\nInternal debugging messages are enabled when $dldebug is set true. Currently setting\n$dldebug only affects the Perl side of the DynaLoader. These messages should help an\napplication developer to resolve any DynaLoader usage problems.\n\n$dldebug is set to $ENV{'PERLDLDEBUG'} if defined.\n\nFor the DynaLoader developer/porter there is a similar debugging variable added to the C\ncode (see dlutils.c) and enabled if Perl was built with the -DDEBUGGING flag. This can also\nbe set via the PERLDLDEBUG environment variable. Set to 1 for minimal information or\nhigher for more.\n\n$dldlext\nWhen specified (localised) in a module's .pm file, indicates the extension which the\nmodule's loadable object will have. For example:\n\nlocal $DynaLoader::dldlext = 'unusualext';\n\nwould indicate that the module's loadable object has an extension of \"unusualext\" instead\nof the more usual $Config{dlext}. NOTE: This also requires that the module's Makefile.PL\nspecify (in \"WriteMakefile()\"):\n\nDLEXT => 'unusualext',\n"
                },
                {
                    "name": "dl_findfile",
                    "content": "Syntax:\n\n@filepaths = dlfindfile(@names)\n\nDetermine the full paths (including file suffix) of one or more loadable files given their\ngeneric names and optionally one or more directories. Searches directories in\n@dllibrarypath by default and returns an empty list if no files were found.\n\nNames can be specified in a variety of platform independent forms. Any names in the form\n-lname are converted into libname.*, where .* is an appropriate suffix for the platform.\n\nIf a name does not already have a suitable prefix and/or suffix then the corresponding file\nwill be searched for by trying combinations of prefix and suffix appropriate to the\nplatform: \"$name.o\", \"lib$name.*\" and \"$name\".\n\nIf any directories are included in @names they are searched before @dllibrarypath.\nDirectories may be specified as -Ldir. Any other names are treated as filenames to be\nsearched for.\n\nUsing arguments of the form \"-Ldir\" and \"-lname\" is recommended.\n\nExample:\n\n@dlresolveusing = dlfindfile(qw(-L/usr/5lib -lposix));\n"
                },
                {
                    "name": "dl_expandspec",
                    "content": "Syntax:\n\n$filepath = dlexpandspec($spec)\n\nSome unusual systems, such as VMS, require special filename handling in order to deal with\nsymbolic names for files (i.e., VMS's Logical Names).\n\nTo support these systems a dlexpandspec() function can be implemented either in the dl*.xs\nfile or code can be added to the dlexpandspec() function in DynaLoader.pm. See\nDynaLoaderpm.PL for more information.\n"
                },
                {
                    "name": "dl_load_file",
                    "content": "Syntax:\n\n$libref = dlloadfile($filename, $flags)\n\nDynamically load $filename, which must be the path to a shared object or library. An opaque\n'library reference' is returned as a handle for the loaded object. Returns undef on error.\n\nThe $flags argument to alters dlloadfile behaviour. Assigned bits:\n\n0x01  make symbols available for linking later dlloadfile's.\n(only known to work on Solaris 2 using dlopen(RTLDGLOBAL))\n(ignored under VMS; this is a normal part of image linking)\n\n(On systems that provide a handle for the loaded object such as SunOS and HPUX, $libref will\nbe that handle. On other systems $libref will typically be $filename or a pointer to a\nbuffer containing $filename. The application should not examine or alter $libref in any\nway.)\n\nThis is the function that does the real work. It should use the current values of\n@dlrequiresymbols and @dlresolveusing if required.\n\nSunOS: dlopen($filename)\nHP-UX: shlload($filename)\nLinux: dldcreatereference(@dlrequiresymbols); dldlink($filename)\nVMS:   lib$findimagesymbol($filename,$dlrequiresymbols[0])\n\n(The dlopen() function is also used by Solaris and some versions of Linux, and is a common\nchoice when providing a \"wrapper\" on other mechanisms as is done in the OS/2 port.)\n"
                },
                {
                    "name": "dl_unload_file",
                    "content": "Syntax:\n\n$status = dlunloadfile($libref)\n\nDynamically unload $libref, which must be an opaque 'library reference' as returned from\ndlloadfile. Returns one on success and zero on failure. This function is optional and may\nnot necessarily be provided on all platforms.\n\nIf it is defined and perl is compiled with the C macro \"DLUNLOADALLATEXIT\" defined, then\nit is called automatically when the interpreter exits for every shared object or library\nloaded by DynaLoader::bootstrap. All such library references are stored in @dllibrefs by\nDynaLoader::Bootstrap as it loads the libraries. The files are unloaded in last-in,\nfirst-out order.\n\nThis unloading is usually necessary when embedding a shared-object perl (e.g. one configured\nwith -Duseshrplib) within a larger application, and the perl interpreter is created and\ndestroyed several times within the lifetime of the application. In this case it is possible\nthat the system dynamic linker will unload and then subsequently reload the shared libperl\nwithout relocating any references to it from any files DynaLoaded by the previous\nincarnation of the interpreter. As a result, any shared objects opened by DynaLoader may\npoint to a now invalid 'ghost' of the libperl shared object, causing apparently random\nmemory corruption and crashes. This behaviour is most commonly seen when using Apache and\nmodperl built with the APXS mechanism.\n\nSunOS: dlclose($libref)\nHP-UX: ???\nLinux: ???\nVMS:   ???\n\n(The dlclose() function is also used by Solaris and some versions of Linux, and is a common\nchoice when providing a \"wrapper\" on other mechanisms as is done in the OS/2 port.)\n"
                },
                {
                    "name": "dl_load_flags",
                    "content": "Syntax:\n\n$flags = dlloadflags $modulename;\n\nDesigned to be a method call, and to be overridden by a derived class (i.e. a class which\nhas DynaLoader in its @ISA). The definition in DynaLoader itself returns 0, which produces\nstandard behavior from dlloadfile().\n"
                },
                {
                    "name": "dl_find_symbol",
                    "content": "Syntax:\n\n$symref = dlfindsymbol($libref, $symbol)\n\nReturn the address of the symbol $symbol or \"undef\" if not found. If the target system has\nseparate functions to search for symbols of different types then dlfindsymbol() should\nsearch for function symbols first and then other types.\n\nThe exact manner in which the address is returned in $symref is not currently defined. The\nonly initial requirement is that $symref can be passed to, and understood by,\ndlinstallxsub().\n\nSunOS: dlsym($libref, $symbol)\nHP-UX: shlfindsym($libref, $symbol)\nLinux: dldgetfunc($symbol) and/or dldgetsymbol($symbol)\nVMS:   lib$findimagesymbol($libref,$symbol)\n"
                },
                {
                    "name": "dl_find_symbol_anywhere",
                    "content": "Syntax:\n\n$symref = dlfindsymbolanywhere($symbol)\n\nApplies dlfindsymbol() to the members of @dllibrefs and returns the first match found.\n"
                },
                {
                    "name": "dl_undef_symbols",
                    "content": "Example\n\n@symbols = dlundefsymbols()\n\nReturn a list of symbol names which remain undefined after loadfile(). Returns \"()\" if not\nknown. Don't worry if your platform does not provide a mechanism for this. Most do not need\nit and hence do not provide it, they just return an empty list.\n"
                },
                {
                    "name": "dl_install_xsub",
                    "content": "Syntax:\n\ndlinstallxsub($perlname, $symref [, $filename])\n\nCreate a new Perl external subroutine named $perlname using $symref as a pointer to the\nfunction which implements the routine. This is simply a direct call to\nnewXS()/newXSflags(). Returns a reference to the installed function.\n\nThe $filename parameter is used by Perl to identify the source file for the function if\nrequired by die(), caller() or the debugger. If $filename is not defined then \"DynaLoader\"\nwill be used.\n"
                },
                {
                    "name": "bootstrap",
                    "content": "Syntax:\n\nbootstrap($module [...])\n\nThis is the normal entry point for automatic dynamic loading in Perl.\n\nIt performs the following actions:\n\n*       locates an auto/$module directory by searching @INC\n\n*       uses dlfindfile() to determine the filename to load\n\n*       sets @dlrequiresymbols to \"(\"boot$module\")\"\n\n*       executes an auto/$module/$module.bs file if it exists (typically used to add to\n@dlresolveusing any files which are required to load the module on the current\nplatform)\n\n*       calls dlloadflags() to determine how to load the file.\n\n*       calls dlloadfile() to load the file\n\n*       calls dlundefsymbols() and warns if any symbols are undefined\n\n*       calls dlfindsymbol() for \"boot$module\"\n\n*       calls dlinstallxsub() to install it as \"${module}::bootstrap\"\n\n*       calls &{\"${module}::bootstrap\"} to bootstrap the module (actually it uses the\nfunction reference returned by dlinstallxsub for speed)\n\nAll arguments to bootstrap() are passed to the module's bootstrap function. The default code\ngenerated by xsubpp expects $module [, $version] If the optional $version argument is not\ngiven, it defaults to \"$XSVERSION // $VERSION\" in the module's symbol table. The default\ncode compares the Perl-space version with the version of the compiled XS code, and croaks\nwith an error if they do not match.\n"
                }
            ]
        },
        "AUTHOR": {
            "content": "Tim Bunce, 11 August 1994.\n\nThis interface is based on the work and comments of (in no particular order): Larry Wall, Robert\nSanders, Dean Roehrich, Jeff Okamoto, Anno Siegel, Thomas Neumann, Paul Marquess, Charles\nBailey, myself and others.\n\nLarry Wall designed the elegant inherited bootstrap mechanism and implemented the first Perl 5\ndynamic loader using it.\n\nSolaris global loading added by Nick Ing-Simmons with design/coding assistance from Tim Bunce,\nJanuary 1996.\n",
            "subsections": []
        }
    },
    "summary": "DynaLoader - Dynamically load C libraries into Perl code",
    "flags": [],
    "examples": [],
    "see_also": []
}