VS2008 win32 project defaults - remove default precompiled headers - c++

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?

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)

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.

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

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.

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.

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.

Related

compile single c++ source file in 1 project in visual studio

i know a lot of people asked this question, but i can't find how to do it. Is there
a way to build only one source file in visual studio 2017? without new project, i'm learning c++, so i can't make huge thing now, just focus to code(now i'm learn data structure and algorithm),most of my exercise is about <200 code lines, so it great to compile new file without whole project, sometimes i need a few lines of code to test my algorithm,please help me, thanks all you guy, because v.s is very good ide so i want to stick with it.
If you just have one file and want to build it without waiting 1-2 minutes for the IDE to pop up,
Find the Developer Command Prompt in your list of applications - it is under the Visual Studio directory in the Application menu.
cd /d to your directory. cd will take you here if you are on the same drive as visual studio. If you are on a different drive, use cd /d.
Use your favourite editor (notepad, vim, geany, notepad++, nano, microemacs etc) to create the file.
cl sourcefile
Run the excutable.
Unlike what visual studio does, you executable will now be in the same directory as your source. Editors like geany have a build button (the brick icon). All you need to do is fill in how to build: in this case, the cl command.
If you want a one file project, just follow these steps.
Create New Project - File -> New -> Project
Fill in filename, select Win32 Console Application. Note the directory - if it is not where you want it, change it. Click OK
Application Wizard pops up, click Next
Application settings - select Empty project, click Finish
Open Solution Explorer. Right click Source Files. Menu pops up, select Add -> New Item
Add new item dialog pops up, fill in your filename.
If you don't know how to create a new project and a new solution, it will be good to learn those basic concepts and use them to write, test, and debug your code.
You can use one Visual Studio project to do all the learning.
Let's say you want to test "algorithm 1". Then,
Create a header file for it and a source file for it -- call them "test-algorithm-1.hpp" and "test-algorithm-1.cpp".
Add them to the project.
#include the header file in the main .cpp file of the project.
Call the function to test "algorithm 1" from main.
#include "test-algorithm-1.hpp"
int main()
{
test_algorithm_1();
}
When you are ready for testing "algorithm 2", repeat the above steps. The main .cpp file can now be.
#include "test-algorithm-1.hpp"
#include "test-algorithm-2.hpp"
int main()
{
test_algorithm_1();
test_algorithm_2();
}
If you want to avoid testing "algorithm 1" while testing "algorithm 2", simply comment out the corresponding line in main.
int main()
{
// test_algorithm_1();
test_algorithm_2();
}
On the source file you don't want to be included in the project, simply right click, select Properties. There you will find in General a field 'Excluded From Build'. Type true/yes there and the source file will be deactivated.

Why is '.editorconfig' not doing anything in Visual Studio 2017?

I have the following version of Visual Studio:
Microsoft Visual Studio Community 2017 Version 15.1 (26403.7) Release
VisualStudio.15.Release/15.1.0+26403.7
I created a new project and added a .editorconfig file at my solution base folder.
Its content is the following:
root = true
[*.cs]
indent_style = space:warning
indent_size = 12:warning
# C# and Visual Basic code style settings:
[{*.cs,*.vb}]
dotnet_style_qualification_for_field = false:warning
The file location should be right:
.editorconfig <-- Here it is
ApplicationInsights.config
App_Data
App_Start
bin
Content
Controllers
favicon.ico
fonts
Global.asax
Global.asax.cs
Models
obj
packages.config
Properties
Scripts
Startup.cs
Views
Web.config
Web.config.backup.1
Web.Debug.config
Web.Release.config
WebApplication8.csproj
WebApplication8.csproj.user
But whenever I edit a .cs file, nothing special happen (despite indentation not following the rule), I expect a warning (after a build, for instance) to show up, but no.
Is there something wrong with my configuration, or is there something which could hinder the configuration from being applied?
I had this same problem. The solution was adding the .editorconfig file to the solution in my case. You can choose to either add it to the solution or the project, depending on whether you want it applied everywhere or just the individual project.
Solution Explorer → right-click your solution or project → Add → Existing Item... (if you have the .editorconfig file in position at the root of the solution or project) or New Item... (then search for editorconfig in the Add New Item wizard and choose the appropriate type for your work).
I solved a similar issue by placing the .editorconfig file at the root folder of the project, i.e., the same folder as your .sln file.
Try to put the .editorconfig file into the same folder as your source file. If it helps, try to move it up (into one of the parent directories) until you get it high enough to affect all the files you need.
If you have any EditorConfig extensions installed, try to uninstall them. There were some related bugs reported.
I had a similar problem and this is how I solved it:
My solution folder had a parent folder named between square brackets [], like [ParentFolderName], so I removed the square brackets and everything worked as expected.
For a reason or another, the editorconfig file does not do anything when the solution folder has a parent folder named between square brackets. The IDE (in my case Visual Studio 2017) uses its settings.

When debugging a visual c+ program, the file specified can't be executed

I made a simple hello world program. I clicked on "Start Debugging" and the window showed "Project is out of date. Would you like to build it?" As I click on "yes", the next window shows "There were build errors. Would you like to continue and run the last successful build?". I choose yes again, and it shows this window: (attached screenshot)enter image description here
There were build errors. Would you like to continue and run the last successful build?
The only correct answer to that question is "No". If you clicked "Debug", you obviously want to debug the current version of the source, not some stale old version that won't match what you're seeing in the editor.
Disable this nonsense message in Tools → Options → Projects and Solutions → Build and Run. For "On Run, when projects are out of date", set it to "Always build". For "On Run, when build or deployment errors occur", set it to "Do not launch".
I cannot think of a reason why you ever want the other options as default settings. If you want to launch an old, stale build, you can always do so manually.
I choose yes again, and it shows this window: "The system cannot find the file specified."
Yet another reason why this is a stupid setting. The second one in particular, the one that controls Run behavior when build errors occur.
What happens is, when you tried to build the project, the first step was to do a clean, which effectively means delete the old files. With the old files gone, it kicks off a build. The build fails, you get an error. You ask it to ignore the error and run an old version. But wait! The old version got deleted at the start of the build, so it no longer exists!
If a build fails, return to the IDE, fix the errors, and then relaunch to rebuild.
Bonus: The build error that you're getting is "fatal error C1010", which is a rather silly error that can be very confusing to those unaccustomed to Visual Studio. Basically, what it's telling you is that because you are using precompiled headers (the default for new projects), the very first line in every source file needs to be the inclusion of your precompiled header. By default, it is named stdafx.h, so the first line in your code file should be:
#include "stdafx.h"
This should go before you include the system header <iostream>. The precompiled header must be included at the very top of the file, or you'll get a build error.
If you do not like that, then you can turn off precompiled headers:
Right-click on your project in the Solution Explorer, and choose Properties.
At the top, click the "Configuration" combobox and select "All Configurations".
Expand "C/C++" in the tree view, and select "Precompiled Headers".
Set the top option, "Precompiled Header", to "Not Using Precompiled Headers".
Sorry: your last successful build was deleted earlier - possibly as a result of an attempted compile/link. You need to fix the source code that you've got now before you've got anything to debug...
It seems to appear that some .dll files are missing for the debug mode for many users.
You don't need to run the debug mode for this, if your program works on normal running, then let it run.
I also can see that you wrote void main() but in C++ the good syntax is int main() and terminated by a return 0; instruction. By the way, think about letting at least a space between #include and the libraries like <iostream> here.

Changing output directory in VS2010 project doesn't work

I have combined several projects into one solution. I created empty solution and added these projects and here is a blue print of how it looks like:
Root:
Project1 - directory
Project2 - directory
Debug - directory
Main.sln - file
Now I want to direct the executable and dll from both projects to \debug folder shown up of the solution file. I go into project properites >> Configuration Properities >> General >> 'Output Directory' and change the output directory to $(SolutionDir)$(Configuration)\ which is default for a new project.
The problem is that it has no effect on where the output file is created, it is still created in the old destination. The old path for `Output Directory' was .\Debug\ not that it matters.
Could this be because the SolutionDir & Configuration may not be defined? Where can I see their definition or values? I also want to create a new configuration which would be 'Release with Debug' how can I create that using environment variable? Thanks!
My project is MFC/Visual C++.
Add-on:
Where are these identifiers like SolutionDir defined in the scrip? I look up for in .vcxproj file but there is mention of it. I create a new dummy VS2010 project just to look at it's .vcxproj file but these project settings identified are not defined in any place that I can see!
This is most likely caused by specific settings overriding global settings, namely Linker's "output" setting. This happens often as a result of conversion from earlier Visual Studio.
What you need is to go through every setting, paying attention to those whose values are written in bold, and reset to default (select it from dropdown) every setting with 'debug' or 'release', and others as necessary.
There could also be specific settings on files. I usually resolve this by opening project in notepad and removing any excessive settings. Just be careful. Using multiline replace in Notepad++ or any other capable editor helps.
I think I had a similar problem.
What I ended up doing was editing the vcxproj file directly. Find this section and edit it like this for each of your configurations:
<PropertyGroup>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
</PropertyGroup>
I had a similar problem with the Intermediate Directory setting in one of my VS2010 projects. No matter what I set it to, it would always use the default value of $(SolutionDir)$Configuration. Oddly, other projects in the same solution with the same settings worked just fine.
After playing around, I stumbled upon a solution.
Click on the setting in the propery page dialog.
Click on the down arrow button in the right-hand side of the edit box.
Select "inherit from parent or project defaults".
Click "Apply".
Click on the setting and change it to your desired value.
I don't know why this works, but it does. It seems like the macros were not being properly evaluated for whatever reason. Then, after you apply the inherited values, it seems to reset itself and start evaluating the macros properly.

VC++ Visual Studio 2010 AssemblyName

I'm creating an automated build system for a group of projects. Most are C# and VB but we have a few VC++. I need to extract the AssemblyName properties for all of the projects before the build starts to perform some custom stuff. The C# and VB projects have an AssemblyName element inside the .csproj and .vbproj files and I can grab them using xml dom. There is no equivelant in the .vcxproj file. How do I figure out what the AssemblyName is going to be for a VC++ project by just looking at the project file (vcxproj) or the files included in the project? Does the compiler simply use whatever file contains the main entry point as the AssemblyName?
e.g. Win32ConsoleApp1.cpp -> Win32ConsoleApp1.exe?
Thanks, those elements were not in my .vcxproj. Perhaps you have an older .vcproj? Anyway it did lead me to find <TargetName/> in the Microsoft.Cpp.props file that is imported into every .vcxproj file. In there is the following line:
<TargetName Condition="'$(TargetName)' == ''">$(ProjectName)</TargetName>
This was no good for my goal of retrieving the name of the assembly that will ultimately be generated because the value $(ProjectName) is expanded during runtime. So I started tracking down were ProjectName is set. It’s in Microsoft.Common.targets and is set to $(MSBuildProjectName). Again no use to me because that too is expanded during run time. I then had to disassemble MSBuild.exe, its dependents, and finally found the Microsoft.Build.Evaluation.Evaluator class were MSBuildProjectName it is set. It’s simply the project file’s name minus the extension. E.g. MyConsoleApp1.vcxproj -> MyConsoleApp1.
I also did some experimenting and by simply right clicking my VC++ project in Visual Studio and selecting “rename” and saving the project a new element is added to the project file called <ProjectName/> with the new value I entered. So based on all of this the logic I’m going with is to parse the .vcxproj file and look for the <ProjectName/> element. If it’s in there then use it; if not simply use the project file’s name minus the extension.
This actually is in the .vcxproj file, under the headings <TargetName> and <TargetExt>. The default settings will be $(ProjectName) and .exe (for an application). The name is actually, by default, named based on the project, not a .cpp file.
However, if the user changes this (in ConfigurationProperties->General), you'll see, in the XML, something like:
<TargetName>$(ProjectName)</TargetName>
<TargetExt>.exe</TargetExt>