Install BerkeleyDB on Strawberry Perl
时间:2008-07-29 来源:xktop
Download and install the Oracle/Sleepycat BerkeleyDB for win32
http://www.oracle.com/technology/software/products/berkeley-db/htdocs/popup/db/4.6.21/db-msi.html
Please use version 4.6.21 or later, because I fail to do the same installation process by using BerkeleyDB version 4.4.20.
1.Go to BerkeleyDB directory
Copy the include directory to C:\strawberry\c\include and rename it from include to db
Copy the lib\libdb46.lib file to C:\strawberry\c\lib and rename it from libdb46.lib to libdb.a
Comment out two typedef lines in C:\strawberry\c\include\db\db.h
line 115: /*typedef u_int32_t uintptr_t;*/
line 128: /*typedef int32_t ssize_t;*/
2. Install the BerkeleyDB sources
C:\>cpan
cpan>install BerkeleyDB --will not succeed because we don’t change configuration
cpan>look BerkeleyDB --only download source and go into the source directory, not try to install, please use this command
when source download is done and directory has been changed, please pause on this command window and do step 3
3. Edit the config.in file
INCLUDE=C:\strawberry\c\include\db
LIB=C:\strawberry\c\lib
DBNAME=-ldb
4. Compile and install
Go back to previous command window and run:
perl Makefile.PL
dmake
dmake test
If test is ok, please install:
dmake install
After installation, please use below perl script to test if the BerkeleyDB module works well.
use strict;
use lib "C:\strawberry\perl\site\lib\BerkeleyDB";
use BerkeleyDB;
my $db;
$db = new BerkeleyDB::Btree
-Filename => "user.db",
-Flags => DB_INIT_LOCK|DB_CREATE
or die "Cannot open file";
$db->db_put("apple", "red");
my $value;
print $db->db_get("apple",$value);
print $value;
undef $db;
If BerkeleyDB works well, the script should print out “red” on screen.
If you want to uninstall BerkeleyDB 4.6.21 after you got it to work for Perl, please do:
Copy C:\Program Files\Oracle\Berkeley DB 4.6.21\bin\libdb46.dll C:\strawberry\c\bin
Copy C:\Program Files\Oracle\Berkeley DB 4.6.21\bin\msvcp71.dll C:\strawberry\c\bin
Reference: http://win32.perl.org/wiki/index.php?title=Install_DB_File_on_Strawberry_Perl