Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top