views:

408

answers:

5

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:

http://stackoverflow.com/questions/1293538/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  A: 

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

Asaf
As described in the question, the pre-compiled headers checkbox is auto checked as soon as WIN32 PROJECT is selected even if "Empty Project" is checked
Mike Trader
+2  A: 

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.

stijn
+5  A: 

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)

demoncodemonkey
Thank you for that very comprehensive answer. Yes it worked. (The check box behavior is still the same, but the result is as desired)
Mike Trader
A: 

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.

jalf
THat only works for a CONSOLE project. A Win32 project has the behaior described in the question. Do you know of a suitable alternative to the VS2008 IDE?
Mike Trader
+1  A: 

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.

Kovey