Perl DynaLoader.pm: The specified module could not be found

Question: I get the following error when trying to install the Chilkat Perl 5.24 module in ActiveState Perl on Windows

C:\chilkat-9.5.0-perl-5.20-x86_64-mingw32>perl Makefile.pl
Checking if your kit is complete...
Looks good
Generating a dmake-style Makefile
Writing Makefile for chilkat
Writing MYMETA.yml and MYMETA.json
 
C:\chilkat-9.5.0-perl-5.20-x86_64-mingw32>dmake
cp lib/chilkat.dll blib\lib\chilkat.dll
cp lib/chilkat.pm blib\lib\chilkat.pm
 
C:\chilkat-9.5.0-perl-5.20-x86_64-mingw32>dmake install
Appending installation info to C:\Perl64\lib/perllocal.pod
 
C:\chilkat-9.5.0-perl-5.20-x86_64-mingw32>dmake test.pl
`test.pl' is up to date
 
C:\chilkat-9.5.0-perl-5.20-x86_64-mingw32>perl test.pl
Can't load 'C:/Perl64/lib/auto/chilkat/chilkat.dll' for module chilkat: load_file:The specified module could not be found at C:/Perl64/lib/DynaLoader.pm line 194.
at C:/Perl64/site/lib/chilkat.pm line 11.
Compilation failed in require at test.pl line 1.
BEGIN failed--compilation aborted at test.pl line 1.

Answer

The line of code in chilkat.pm (line 11) that is failing is “bootstrap chilkat

package chilkat;
use base qw(Exporter);
use base qw(DynaLoader);
package chilkatc;
bootstrap chilkat;
package chilkat;
@EXPORT = qw();

The bootstrap function is typically found in the .pm file of a Perl module. The actual implementation is provided by the DynaLoader module, which handles the dynamic loading of shared libraries.

When bootstrap chilkat is executed, DynaLoader locates the shared library (chilkat.dll) and loads it into memory. The module’s initialization function (boot_chilkat) is called to set up the mappings between Perl subroutines and the corresponding C functions.

When the bootstrap function is called, DynaLoader follows a specific process to find and load the appropriate shared library for the module. Here’s an overview of how DynaLoader finds the shared library:

Steps DynaLoader Follows

  1. Module Name to File Name Conversion:
    • The bootstrap function converts the module name into a filename that corresponds to the shared library. For example, the module chilkat would correspond to a shared library named chilkat.so on Unix-like systems or chilkat.dll on Windows.
  2. Search Paths:
    • DynaLoader searches for the shared library in directories specified in the @INC array, which contains the list of directories to be searched for Perl modules and libraries.
    • Additionally, it may look in the directories specified by the LD_LIBRARY_PATH (on Unix-like systems) or PATH (on Windows) environment variables.
  3. File Extensions:
    • The module considers various file extensions that are typical for shared libraries on the target operating system. This includes .so, .dll, .dylib, etc.
  4. DynaLoader’s Search Mechanism:
    • The DynaLoader uses the dl_findfile function to search for the shared library file. This function iterates through the search paths and file extensions to find a matching file.
  5. Loading the Library:
    • Once the shared library is found, DynaLoader uses the system’s dynamic loading functions (dlopen on Unix-like systems, LoadLibrary on Windows) to load the shared library into memory.
    • After loading, DynaLoader calls the module’s initialization function (typically named boot_chilkat) to set up the Perl bindings to the C functions.