April 12, 2006

Installing the Crypt::Rijndael Perl module on a Windows box

I was working on an update to my multi-language encryption samples and i needed to test my Perl scripts. Last time i did it i just ran my Perl samples on my home Mac, but this time around i was at work. I figured i could just quickly install ActivePerl and give it a try. Then install went find but when i tried to use their Perl Package Manager (PPM) to install the encryption library, i discovered that the encryption libraries aren't available through PPM. So instead, i opened up a command prompt and tried cpan install Crypt::Rijndael however that failed. The error i got informed me that "nmake is not recognized as an internal or external command."

[Note that i'm presenting this information in roughly the same order i figured it out. If you want the short version, jump to the end.]

If the module in question only needed to use the nmake functionality, you can build your project by downloading a copy from Microsoft and adding it to your Perl bin folder. I tried this but then soon learned that wouldn't work. I got a new error telling me that "cl is not recognized as an internal or external command" which terminates the nmake process with fatal error code U1077.

I found out that this meant that the make routine needed to compile some C files that were downloaded with the module. This means you are going to have to have a C-compiler on your machine. Luckily, one is included with Visual Studio (VS) which i happen to have installed. You must have installed the Visual C++ module (which by default installs along with VB.NET and C#). Note that VS also includes a copy of nmake as well. In order for the installation process to work, you're going to have to make sure your environment variables are set up correctly. (If you dont have Visual Studio with Visual C++ installed, check out this article on building Perl itself on Windows for other compilation suggestions.)

First, you need to set the PATH variable to include the directory where your VS C++ command line tools live. This folder will contain both nmake and cl. I happen to have both VS 2003 and VS 2005 installed on my box. The respective paths on my machine happened to be C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin and C:\Program Files\Microsoft Visual Studio 8\VC\bin. You simply need to add just one of the two. If you had any existing paths in your PATH environment variable, these new ones can be added by simply inserting a semicolon between them. If you change your environment variables via the Windows GUI interface, be sure to close and reopen any command prompt windows for the changes to take place.

If you only set the PATH variable, you will get an error when trying to make the file that says that "mspdb80.dll was not found" (or "mspdb71.dll was not found" if you used VS 2003 rather than VS 2005). This is because there are more environment variables that need to be set up. Luckily, there is a batch file in the bin folder we added to the path that will set the rest of the environment variables up. At a command prompt, type vcvars32. Do this just before you run the CPAN command. That will set up everything you need to be able to build from the command line.

I did have a few other problems that popped up as well. At one point i kept getting a "cannot copy file" error message during the build process. It turns out that the Microsoft Index Server was locking my files. It might be a good idea to disable it when building modules (Control Panel -> Administrative Tools -> Services -> Indexing Service -> Stop). Alto note that if you have a bad build, it's a good idea to run clean Crypt::Rijndael within CPAN before trying again. This helped to clear up several errors during my various tests.

In summary, here are the steps required: 1) Verify that you have the path to the VS C++ command line tools set up in your PATH environment variable (VS 2003: C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin or VS 2005:C:\Program Files\Microsoft Visual Studio 8\VC\bin ). 2) Open a command prompt (Start -> Run -> "cmd") and type vcvars32 to set up the build environment. 3) Finally, run cpan install Crypt::Rijndael.

Posted by Matthew at April 12, 2006 02:21 PM
Comments

Thanks. Very useful.

Posted by: Someone at November 23, 2007 04:59 PM