Wednesday, July 6, 2011

Fixing NMAKE fatal error U1077

Here's how to fix the following bug:

NMAKE : fatal error U1077: 'cl.EXE' : return code '0x1'

or

NMAKE : fatal error U1077: 'cl.EXE' : return code '0x2'

or

NMAKE : fatal error U1077: 'cl.EXE' : return code '0xc0000135'

I encountered this while building OpenSSL with Visual Studio 2005 on Windows 7 (I ran "nmake -f ms\ntdll.mak /x C:\out.log" if anyone's curious).

According to google, to fix this I needed to run "vsvars32.bat" before I ran name nmake. Only, for some reason the Visual Studio 2005 command prompt wanted to run nmake in a separate window, and since the new window didn't know about the old window's updated PATH, nmake produced first error (return code 0x1 - can't find cl.exe at all).

The actual solution is to make sure you always run the Visual Studio 2005 command prompt as an Administrator. But, if for some reason that still doesn't work and you really want to bash Windows with a hammer, here's how to do it:

Irritated, I opened "vsvars32.bat" in Notepad++ to see exactly what it was supposed to do. Basically:

@set DevEnvDir=C:\Program Files\Microsoft Visual Studio 8\Common7\IDE

@set PATH=C:\Program Files\Microsoft Visual Studio 8\Common7\IDE;C:\Program Files\Microsoft Visual Studio 8\VC\BIN;C:\Program Files\Microsoft Visual Studio 8\Common7\Tools;C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\bin;C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\bin;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin;C:\Windows\Microsoft.NET\Framework\v2.0.50727;C:\Program Files\Microsoft Visual Studio 8\VC\VCPackages;%PATH%

@set INCLUDE=C:\Program Files\Microsoft Visual Studio 8\VC\ATLMFC\INCLUDE;C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE;C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\include;%INCLUDE%

@set LIB=C:\Program Files\Microsoft Visual Studio 8\VC\ATLMFC\LIB;C:\Program Files\Microsoft Visual Studio 8\VC\LIB;C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\lib;%LIB%

@set LIBPATH=C:\Windows\Microsoft.NET\Framework\v2.0.50727;C:\Program Files\Microsoft Visual Studio 8\VC\ATLMFC\LIB

This pissed me off. There's no reason I can think of why VS8's nmake shouldn't always do this when it runs (or at very least there should be a flag for it). So, being pissed off, I added all the above to my System Variables, forced windows to refresh my PATH settings, told Windows to suck it, and voila, nmake worked as expected!

Anyway. I wanted to throw this explanation out there in case random a googler finds him or herself stuck as to why the prescribed fix wasn't working. If you bang up your PATH at all, just remember to undo the damage once you're done (even though it feels good at the time, it always seems to cause problems later; silly OS).

0 comments: