I am trying to use a Win32 dll in a perl script using Win32::API module.
For this I have written a perl script like this
use Win32::API;
$Win32::API::DEBUG = 1;
$function = Win32::API->new(
'mydll.dll', 'int func()',
);
$return = $function->Call();
But I am getting the following error:
Win32::API::new: Loading library 'mydll.dll'
FAILED Loading library 'mydll.dll': The specified module could not be found.
Can't call method "Call" on an undefined value at .\test_dll.pl line 6.
Although the script and the dll are at the same location, so there is no way it can't find the dll. Also i have tried using the full path.
I am using active perl 5.16 on Windos 7 platform. I have tried this with 5.14 too without any help
What is happening here?
This is resolved after adding the other dependent dlls to the same place as it is .
Related
I have a perl program that uses WWW::Mechanize::Firefox on windows 7 32bit with strawberry perl.
It works fine with the command C:\>perl testcase.pl. When I compile it with C:\>pp -o testcase.exe testcase.pl it compiles with no errors.
When I run the testcase.exe it gives me the error:
Failed to connect to , Can't locate object method "setup" via package "MozRepl::Client" at MozRepl.pm line 224
The code I am using for testcase.pl is:
#!perl
use MozRepl;
use WWW::Mechanize::Firefox;
use warnings;
system('start firefox');
sleep(5);
$mech = WWW::Mechanize::Firefox->new;
Also note that a program without WWW::Mechanize::Firefox and MozRepl does work fine.
The problem has obviously been narrowed down to PAR::Packer not liking MozRepl, any idea what it might be?
PAR::Packer sometimes has a hard time identifying which modules need to be included in a PAR package in order to fulfill all of the requirements of the program you are trying to package.
It copes OK if the dependancies are loaded via plain 'use', or 'require' statements where the module to be loaded is a literal string, but it won't have much chance if the module is being loaded dynamically with something like:
require $myModuleToLoad;
Browsing the source code of MozRepl and related modules shows that they make heavy use of plugins loaded dynamically. I suspect that some of these are not being packaged.
You can manually specify module(s) to be included in the PAR package by adding -M Module::Name to the pp command line for each of the modules to be added (replacing Module::Name with the actual module name of course).
The hard part might be identifying which modules to include. One way to do this is to temporarily add something like this to the end of your script:
END { print "$_ -> $INC{$_}\n" foreach sort keys %INC; }
then run your script normally, not through PAR. It should list all the modules that were loaded. You can compare that with the actual modules present in the PAR package and add the missing ones using the -M option to pp.
You can see the modules inside your PAR file by opening it with an unzipping tool, such as 7zip. Or in Linux:
unzip -l {parfile}
I am running a Perl program that uses Math::Vector,
but I am getting the following error.
Can't locate object method "UnitVecPoints" via package "Math::Vector"
at /usr/local/share/perl5/Math/Vector.pm line 135.
How do I proceed? The module is correctly installed.
The module is no longer on CPAN. I found it on backpan, though: http://backpan.perl.org/authors/id/W/WS/WSYVINSKI/Vector.pm
It seems to call UnitVecPoints, but it only defines UnitVectorPoints. Try to edit the file /usr/local/share/perl5/Math/Vector.pm, providing the correct subroutine name.
I'm trying to get the resolution,width,height of the images in the specific file.
I have the following code.
#use strict;
use Image::Info qw(image_info dim);
use File::List;
#perl2exe_include Image::Info::JPEG;
#perl2exe_include PerlIO;
my $file = <ImageFilePath>;
my $info = image_info($file);
my $res = $info->{resolution};
print "$$res[0]\n";
I have the Perl Version 5.16.3
I get the following error:
Can't locate Image/Info.pm in #INC (#INC contains: c:\program files\Perl\lib c:/program files/Perl/site/lib c:/program files/Perl/lib .) at Img_Res.pl line 3.
BEGIN failed--compilation aborted at Img_Res.pl line 3.
Can anyone give me the solution to this?
From the code part of question I am concluding that you are trying to create an executable using Perl2EXE, because you are using the line
#perl2exe_include Image::Info::JPEG;
and also assuming that you are running command
perl2exe c:\somepath\somescript.pl -o somescript.exe
The answer from #James Green is correct to an extent, however its incomplete (as in fails to explain his second bullet point).
You need to install "Image::Info" and any other modules that you are using (Use the answer from #James Green).
After installation, Open to windows explorer and locate the module that you just installed,
It will normally be in the following folders
"PERL_PATH\perl\lib"
"PERL_PATH\perl\site\lib"
"PERL_PATH\perl\vendor\lib"
Once you locate the module is installed in the one of the 3 locations above. Navigate to the location where Perl2EXE is installed.
PERL2EXE_PATH\perl2exe-XX.xx-Win\
Locate the folder with the current version of perl you are using. In your case the folder name should be
Win32-5.16.3 or Win64-5.16.3
Open the folder and locate the .conf file.
Edit the line with header libdir.
libdir=perl-Win32/site/lib;perl-Win32/lib;perl-Win32/vendor/lib;.
Ensure all the perl/lib directories are included in the search path.
Save it and rerun your command. This should work.
Sometimes even after all this the perl2exe command fails, this is due to the limitation of the program being able to decipher the qw command.
So to avoid this directly call the module (ex: use Module::Name;) in your code instead of using the qw.
You need to ensure you've done two things:
install the Image::Info module
make sure #INC includes the path to wherever you installed the module
I see you're on Windows, which means you're likely using either Strawberry Perl, or ActiveState's Perl. If you're using Strawberry Perl you should have some success following the directions on http://www.cpan.org/modules/INSTALL.html -- I believe ActiveState has its own built-in package manager, ppm, and to get started with that you'll want to look here: http://www.activestate.com/activeperl/ppm-perl-modules
I have inherited a web project that is perl based and I'm attempting to set up a local testing server so changes can be made internally to the project.
The server architecture
Ubuntu 9.10
php 5.2.10
mysql 5.1.37
perl 5.10.0-24ubuntu4
All the dependent modules and packages are installed such as DateTime.pm, TemplateToolkit.pm but running the application throws the following error message:
Can't locate object method "new" via package "Template" (perhaps you forgot to load "Template"?) at ../lib//KPS/TemplateToolkit.pm line 51
The code block that this refers to is:
sub new {
return Template->new(
INCLUDE_PATH => $KPS::Config::templatepath,
ABSOLUTE => 1,
DEBUG => 1,
);
}
If anybody is able to shed any light on this or point me in the right direction it would be greatly appreciated.
Thanks
Simnom
You need to load Template Toolkit first, with:
use Template;
To make sure that Template::Toolkit is properly installed on this system, from a console you could run:
perl -MTemplate -e0
If it returns without an error, it means Template.pm wsa loaded succesfully; if not, it will give you an error of "Can't locate Template.pm in #INC...".
An additional thing to check because the accepted answer test could be successful even if you are not setup correctly; make sure that the package declaration in the module has the correct path. The scenario is as follows:
You do
use a::b;
...
a::b->new();
and then in b.pm you do
package b;
You may be banging your head for a while until you realize that you need to do
package a::b;
I have a script that is using DBI to interface with Oracle, but I keep getting the following error:
install_driver(Oracle) failed: Can't
load
'/usr/opt/perl5/lib/site_perl/5.005/aix/auto/DBD/Oracle/Oracle.s
o' for module DBD::Oracle: dlopen:
/usr/opt/perl5/lib/site_perl/5.005/aix/auto/DBD/Oracle/Oracle.so:
can't load library
/usr/opt/perl5/lib/site_perl/5.005/aix/auto/DBD/Oracle/Oracle.so50
/usr/oracle/lib/libclnts h.a shr.o103
/usr/oracle/lib/libclntsh.a shr.ocan't
load library
/usr/oracle/lib/libclntsh.a50
/usr/oracle /lib/libclntsh.a at
/usr/local/lib/perl5/5.6.0/aix/DynaLoader.pm
line 200. at (eval 1) line 3
Compilation failed in require at (eval
1) line 3. Perhaps a required shared
library or dll isn't installed where
expected at ./dbi_test.pl line 9
Line 9 is were id do the prepare
statement in my perl script: my $sth =
$dbh->prepare('Sql statement here')
or die "Couldn't prepare statement: " . $dbh->errstr;
I looked and I have 2 versions of Perl installed in the /usr/opt/perl5/lib/site_perl/ directory:
5.005 and 5.8.0
My boss informed me that the version of AIX installs one version and our version of Oracle installs another. So I'm thinking I'm loading the wrong driver, but am not sure.
Does anyone see what might be the problem?
Any help is appreciated.
It looks like you might have installed the DBI driver under your 5.8 perl installation, but the system is using the 5.005 installation when your script is run (probably due to your PATH setting). Change your path to use the 5.8 executable, and set your PERL5LIB environment variable to include the 5.8 library paths.
If you have to use the 5.005 version, then install DBI under that version as well.