环境变量设置完后需要重新启动 Visual Studio 2008 才有效。
右击example.i,点击Properties中Custom Build Step
设置Command line:
echo In order to function correctly, please ensure the following environment variables are correctly set:
echo PERL5_INCLUDE: %PERL5_INCLUDE%
echo PERL5_LIB: %PERL5_LIB%
echo on
$(SWIG) -perl5 $(InputPath)
#
# Perl5 script for testing simple example use example; # Call our gcd() function $x = 42;
$y = 105;
$g = example::gcd($x,$y);
print "The gcd of $x and $y is $g\n"; # Manipulate the Foo global variable # Output its current value
print "Foo = $example::Foo\n"; # Change its value
$example::Foo = 3.1415926; # See if the change took effect
print "Foo = $example::Foo\n";
测试结果:
The gcd of 42 and 105 is 21
Foo = 3
Foo = 3.1415926
-----------------------------------------------------------------
最后测试的时候出现以下错误:
F:\>perl runme.pl
Can't locate loadable object for module example in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .) at example.pm line 11
Compilation failed in require at runme.pl line 4.
BEGIN failed--compilation aborted at runme.pl line 4.