VS2008 win32 project defaults - remove default pre

2019-05-06 17:25发布

问题:

I have been through every option to try to find a way to get the IDE to let me create a new win32pject without precompiled headers. I have read every thread on this forum with the words "precpmpiled headers" in it and the closest I got was:

Precompiled Headers

Using 2008 pro (not express, althought the behaviour seems to be similar) I go to:

File -> New -> Project

This opens the New Project dialog in which I select Visual C++ Win32 Project, enter a name and hit OK.

THen I get the "Win32 Application Wizard". With the Application Type set to "Windows Application", the application settings pane will not allow me to uncheck the pre-compiled headers. THe check box is greyed out. IF I choose "Console Application" I can uncheck it, but I am creating a GUI app.

WHen I click Finish I get 6 yards of code in xxx.cpp, four header files and the obligatory stdafx.cpp.

Perhaps I could remove and delete all this stuff and the go into the properties and turn off PCH, but thats a hasssel for the many small project examples I want to write.

I just want an empty project that will compile to a win32 app, so how do i change the PCH default to NONE?

回答1:

You could make your own template to do this, or you could edit the default one. The relevant wizard can be found here:

C:\Program Files\Microsoft Visual Studio 9.0\VC\VCWizards\AppWiz\Generic\Application

Obviously if you're gonna edit the default template, backup the folder first.

I'll show you how to get started on editing it.

First of all you need to tell the wizard script that you don't want precompiled headers. Edit this file in your favourite text editor:

\scripts\1033\default.js

Find this line:

var Pch = wizard.FindSymbol("PRE_COMPILED_HEADER");

and comment out some of the lines below it like this:

//  if ((strAppType == "LIB" || ((strAppType == "CONSOLE") && 
//      !wizard.FindSymbol("SUPPORT_MFC") && !wizard.FindSymbol("SUPPORT_ATL"))) && !Pch) 
    {
        AddFilesToProjectWithInfFile(selProj, strProjectName);
        SetNoPchSettings(selProj);
    }
//  else
//  {
//      AddFilesToProjectWithInfFile(selProj, strProjectName);
//      SetCommonPchSettings(selProj);  
//  }

Now open this file:

\templates\1033\Templates.inf

and find the first occurrence of [!else] and delete these 3 lines below it:

stdafx.h
targetver.h
stdafx.cpp

This will give you a project without stdafx.cpp/.h or targetver.h, and the CPP file will not try to use a PCH. However it won't build because we haven't added any #includes to the appropriate header files. I'll leave that for you to figure out :)
(you can edit the files that get generated automatically by modifying the files in \templates\1033)



回答2:

either choose an empty project, or create your own wizard in which you use a template. Since you say you don't want to change properties the whole time, I'd also strongly suggest using property sheets (vsprops). This way, you create an empty project, add the property sheets you want, and you'r ready to go. No more fiddling with properties, and each project uses the same set.



回答3:

Mark the "Empty Project" check box in the "additional options", in the Application Settings dialog.



回答4:

The "Empty Project" option will create a project without precompiled headers. At least, this is what I get on Visual Studio 2008 SP1.

It's true that the "Use precompiled headers" remain checked, but the project will have the property UsePrecompiledHeader="0" and the wizard won't create the files.



回答5:

I'm jumping way late on this bandwagon, as I'm having the same issues for VS2010.

I'm not sure if this solution would apply for VS2008.

Since there are no settings or options under tools which would enable me to default to an empty project, I searched around and found the following:

in the folder

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\VCWizards\AppWiz\Generic\Application\html\1033

there is a file named default.htm

in the </HEAD> section, there are two lines:

<SYMBOL NAME="EMPTY_PROJECT" TYPE=checkbox VALUE=false></SYMBOL>
<SYMBOL NAME="PRE_COMPILED_HEADER" TYPE=checkbox VALUE=true></SYMBOL>

which I replaced with

<SYMBOL NAME="EMPTY_PROJECT" TYPE=checkbox VALUE=true></SYMBOL>
<SYMBOL NAME="PRE_COMPILED_HEADER" TYPE=checkbox VALUE=false></SYMBOL>

(in other words, I just switched true and false on those lines) and now I have an empty project by default when I create a console app.

I don't know the repercussions as to what it will affect when I do something other than console apps, but since I saved the original file, I can just revert to the old M$ settings.



回答6:

You can just select 'empty project' under 'additional options'. Then you get a project with no precompiled headers, and no autogenerated files.

I don't know what it is with Microsoft's obsession with forcing precompiled headers even in the smallest test project. Presumably it's based in the same philosphy that gave us the macro hell that is windows.h, or the way even an empty project overrides two dozen project settings, making property sheets almost useless.

I suspect there's simply a strong mafia inside Microsoft's developer division, who's doing everything they can to prevent Visual Studio from becoming a useful tool for C++ developers. So far, they're doing a very good job of it.