4
votes

I've configured Microsoft Visual Studio to use a Makefile configuration type, and I've written a makefile to build my project using the Microsoft tools. Under the NMake section of the project configuration I've set the build commandline to be build.bat, which is a file which simply invokes nmake with my makefile as command line argument, like so:

nmake /nologo /f makefile.x86.winnt.msvc2010

This works just fine.

For cleaning, I wrote a target in my makefile which deletes all the build artifacts. It looks like this:

#... the rest of the makefile
clean:
    @erase /f /q $(OBJS) $(OUT) $(MAPFILE) $(PDBFILE)
    @echo + clean

So I set the clean command line to be an nmake invocation with clean as an argument. Like this:

nmake /nologo /f makefile.x86.winnt.msvc2010 clean

I placed this text into clean.bat and set it as the "Clean Command Line," but it doesn't work because the invoking shell cannot locate nmake. I checked the path at the time of the clean invocation and MSVS doesn't include the build tools in the path (including nmake) for cleans. (Note that running the above nmake command succeeds from a shell which has nmake in the PATH).

How can I get MSVS to include the build tools in the PATH so I can invoke nmake in the clean command line? Or is there a better solution?

3
I swear the better solution is to not develop on Windows! I have been having similar issues all day with VS2010. - Dan
@Dan I'm doing most of my development from Linux but the project is cross platform and the client wants a windows build. Otherwise I wouldn't bother. - Max DeLiso
I'm in the same predicament. Trying to build open source software on Windows is freakin' ridiculous! I'd use Cygwin if I could but unfortunately that's not an option :( I've wasted so much time on something that's a single apt-get line on Ubuntu. - Dan
The package management is one of the huge ones that Linux does way way better than windoze. rants about benefits of FOSS. Windows 8 is much much more inhospitable than previous incarnations as well. dark days. - Max DeLiso
I'm keeping my fingers crossed that 1) we don't need to support users on Win8, 2) if we do, I can continue to build on Win7 and the resulting program will install/run on Win8. That's one thing that MS seems to do better than Linux -- backwards and forwards binary compatibility. Of course, not really needed on Linux... - Dan

3 Answers

4
votes

Quoting from the Visual Studio Express Readme:

2. Known Issues

2.4. Product Issues

2.4.1. General Issues (Product)

2.4.1.14. Clean Solution does not work for Configuration Type: Makefile (2010 RC)

Doing "Clean Solution" on an nmake solution reports the following error:

1>------ Clean started: Project: makefiletest, Configuration: Debug Win32 ------
1>  'nmake' is not recognized as an internal or external command,
1>  operable program or batch file.
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(33,5):
  error MSB3073: The command "nmake /?" exited with code 9009.
================= Clean: 0 succeeded, 1 failed, 0 skipped ==========

To resolve this issue:

  1. Open the Visual Studio Command Prompt window.
  2. Open Devenv by typing devenv /useenv.
  3. Now "Clean Solution" should work.

Or:

Pass a batch file to the clean command. In the batch file, set up PATH to the nmake tool as well as the other build environment.

3
votes

Of course you are right, MSVC never put its build tools in the path! So you have two options here:

  • Run you batch file from within VisualStudio command prompt

  • Add %ProgramFiles%\Microsoft Visual Studio 10.0\VC\vcvarsall.bat to start of your batch file to add required path to the PATH.

0
votes

I think a better solution is to add set PATH=$(VSInstallDir)\BC\bin;%PATH% to the start of your batch file.

This should future-proof the build if you upgrade to VS2012 (or beyond) in the future.