VS 2010 error - cannot open file "iostream" - c++

I've just migrated from VS2005 to VS2010 and it fails to compile a simple program.
#include <iostream>
using std::cout;
using std::endl;
int main()
{
cout << "Hello Visual Studio 2010 :)" << endl;
}
Errors -
1 error TRK0005: Failed to locate: "CL.exe". The system cannot find the file specified.
2 IntelliSense: cannot open source file "iostream"
3 IntelliSense: name followed by '::' must be a class or namespace name
4 IntelliSense: name followed by '::' must be a class or namespace name
5 IntelliSense: identifier "cout" is undefined
6 IntelliSense: identifier "endl" is undefined
PS: I'm completely new to using VS2010 but have experience in VS 2005.
Here are lists of directories that I added from VS2005 to VS2010 under 'user property sheet'
Executable -
$(VCInstallDir)bin; $(VSInstallDir)Common7\Tools\bin; $(VSInstallDir)Common7\tools; $(VSInstallDir)Common7\ide; $(VSInstallDir); $(VSInstallDir)\SDK\v2.0\bin
Include -
$(VCInstallDir)include; $(VCInstallDir)atlmfc\include; $(FrameworkSDKDir)include
Library -
$(VCInstallDir)lib; $(VCInstallDir)atlmfc\lib; $(VCInstallDir)atlmfc\lib\i386; $(FrameworkSDKDir)lib; $(VSInstallDir); $(VSInstallDir)lib
Source -
$(VCInstallDir)atlmfc\src\mfc; $(VCInstallDir)atlmfc\src\mfcm; $(VCInstallDir)atlmfc\src\atl; $(VCInstallDir)crt\src

I've run into the same issue on a couple of different machines where there were other versions of VS (2005, 2008) already installed. I ended up also getting all sorts of strange errors.
I found the following trick worked for me, maybe it will work in your case too:
- Open a new instance of VS2010
- Create new console application with the def settings.
- Try compile: there should be some errors
- Open the "Property Manager"
- Bring up the Microsoft.Cpp.Win32.user property sheet of the project
- Click on VC++ Directories
- Click on the "Executable Directories" field. That should display a drop down, click on the drop down and select "Edit". You should see a bunch of inherited values that supposedly contain all the required directories similar to the ones you listed above. Uncheck the "Inherit from parent or project defaults" option. Recheck it and click "Ok".
- Repeat this for the includes, library directories, etc.
-Click on "Apply" and "Ok"
- Rebuild the project and check if this worked.
I only needed to do this once. After closing VS and creating a new project, I could just compile. Before I discovered this, I manually removed all inherited values and added absolute paths to all the VS and SDK directories. That also worked, but was a lot more work.

The system could not find the Visual C++ compiler (CL.exe)...
Things you should try:
Rerun the Visual Studio 2010 installer and make sure you selected to install Visual C++ tools for your platform (either x86 or amd64).
Run the installer in repair mode.
If this does not solve your problem:
Try to run Visual Studio 2010 Uninstall Utility (by Microsoft) and then try installing VS 2010 again.

I had the same problem and found this page via a search, but I didn't quite grasp Ralf's answer about the user property sheet, and had no luck with re-installing. I think Ralf's answer would have worked for me, but I was looking at the "Property Pages" dialog that comes up when you right-click on a project in the Solution Explorer and choose "Properties". I didn't realize that it was different from the "Property Manager".
So, I asked on the msdn forum and got an answer and a nice explanation of property sheets. The solution that worked for me was to edit the user property sheet in a text editor and delete all the paths, leaving it empty like this:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>
The user property sheet is Microsoft.Cpp.Win32.user.props under
<localappdata>\microsoft\msbuild\v4.0 where <localappdata> is
c:\users\<username>\appdata\local under Win7.

I have no idea why this worked but I was getting this error and installing Visual Studio Power Commands solved this for me. This extension adds the Configuration Properties -> VC++ Directories that allows you to directly modify the ExecutableDirectories macro, it might have something to do with that.

Related

How to properly delete projects in PlatformIO?

I use PlatformIO with Visual Studio Code on Windows 10.
Now whenever I:
create a Project with a name X
close Visual Studio Code
delete the Project folder X
open Visual Studio Code
create a new Project with the same name X
I get an empty project with a main.cpp file as expected, but the IDE shows an error for the line:
#include <Arduino.h>
The Error says: "Include Error recognised. Update your includePath." (Translated)
However, if I try to build, it compiles just fine. Even uploading and running works.
This include error appears not only with Arduino.h but with all includes, even if the file is in the exact same location. And it appears in other files than just main.cpp as well.
Can you tell me why this happens? How can I reuse the project names of deleted projects? Or If I should not delete projects like this (delete the project folder), how else would I delete a project?
I tried this with multiple project names and different boards, always with the same result.
Things I tried so far:
I found a Folder .cache in the PIO directory. But unfortunately renaming it (after step 3) did not help: after restarting PIO it recreated the folder as expected but the error message is still here.
In the same location there is a file homestate.json that among other things contains the path to recently opened projects. I removed those entries without luck.
I am just starting out with VSCoode and PlatformIO so i can't tell you why all of what you are seeing is happening is happening.
I use VSCode v1.63.0 on Windows 10.
If you want to delete the old project name, reuse it or not, you can bring up the Command Palette under the View menu (Shift-Control-P for me) and search for Workspace: Remove Folder from Workspace...., it will only be listed if you have projects in the workspace. A list of projects will be displayed, selected which one to delete and click on it. There will not be a confirmation prompt.

Linker outfile property file does not match targetpath?

I'm trying to compile a C++ type .DLL for a SierraChart custom study.
(Which is a financial trading application.) Here is the warning I get that I need to fix so it all points to the linker output value:
warning MSB8012:
TargetPath(C:\SierraChart\VCProject\Release\SCStudies.dll) does not match the Linker's
OutputFile property value (c:\sierrachart\data\SCStudies.dll).
This may cause your project to build incorrectly. To correct this, please
make sure that $(OutDir), $(TargetName) and $(TargetExt)
property values match the value specified in %(Link.OutputFile).
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets
Any idea what's wrong?
I believe this warning appears specifically when upgrading a C++ project to VS2010. Visual Studio 2010 C++ Project Upgrade Guide describes some of the caveats encountered during an upgrade. If you're uncomfortable changing project settings, then retaining the older version of Visual Studio, may work for you.
To change the %(Link.OutputFile), open the project properties. Navigate to Configuration Properties -> Linker -> General. You can set the Output File to $(OutDir)\SCStudies.dll, which should take care of your issue. You may need to repeat the change for each Configuration/Flavor you will be building (Debug/x86, Release/x86, Debug/Itanium, etc...).
Based on this answer.
I changed the following property:
Linker -> General -> Output File to
"$(OutDir)$(TargetName)$(TargetExt)"
This prevented the warning to appear and the output was generated successfully.
The original configuration was set like:
Properties -> Linker -> General : $(OutDir)\"<'name fileA>".exe
The program tries to run "<'name_project>".exe and as result error Linked.
You need to set the configuration as:
Properties -> Linker -> General : $(OutDir)\"<'project name>".exe
A different fix which others haven't mentioned is that by default the TargetExt is .exe and for my debug builds I changed it to be _d.exe, where instead you should be doing that in the TargetName path.
The directory specified in General->Output Directory and the directory specified in the path at Linker->Output File have to match.
If you want to change the defaults do things in these order:
You first configure the OutDir in General->Output Directory. E.g.
$(SolutionDir)$(Platform)\$(Configuration)\MyProgram\
Make sure Output File is consistent. E.g. this would work
$(OutDir)\$(TargetName)$(TargetExt)
The comment from Gerardo Hernandez helped me.
The directory specified in General->Output Directory and the directory specified in the path at Linker->Output File have to match.
In my case I was importing a large project from Visual Studio 6 and
C:\Project\myproject\OneOfMyDlls\.\Debug\OneOfMyDlls.dll
was not equal to
C:\Project\myproject\Debug\OneOfMyDlls.dll
but
C:\Project\myproject\OneOfMyDlls\..\Debug\OneOfMyDlls.dll
would have been, after path reduction.
The problem was that the Visual Studio 2017 import had changed the output directory from
..\Debug to .\Debug assuming that the unconventional parent directory use was a mistake. In a large project with 13 DLLs of our own, (never mind second and third party DLLs too), it makes sense to collect all the DLLs in one place and ..\Debug was correct.
So while others might have had to change Linker->Output File, in my case it was General->Output Directory which needed to change as it had been corrupted by the import from Visual Studio 6.
Something like ..\Debug had become something like .\Debug after import. (The real project specific names have been removed .)
Looks like it's not significant for the program:
Odd Visual Studio error when following the custom study video
If, like me, you return to Visual Studio after 20 years, you may not know where the project properties are. In VS 2012: top of the screen "FILE EDIT VIEW PROJECT BUILD..." : choose PROJECT. Properties is the last item in the menu. Indeed for me there was a mismatch in the target name, too.

What are C2471,C1083 errors related to a VC2008 project and how to correct them

I had a VC2008 project very complicated.Inorder to understand it's inner workings I tried to simplify it and now I am getting 289 errors of the following type for most of the files:
Error 5 error C2471: cannot update program database 'c:\users\ryan\documents\visual studio 2008\projects\vc\myinfo\cli\debug\vc90.pdb' c:\users\ryan\documents\visual studio 2008\projects\vc\myinfo\cli\mediainfo\file__analyze_buffer_minimizesize.cpp 1 CLI
Error 6 fatal error C1083: Cannot open program database file: 'c:\users\ryan\documents\visual studio 2008\projects\vc\myinfo\cli\debug\vc90.pdb': No such file or directory c:\users\ryan\documents\visual studio 2008\projects\vc\myinfo\cli\mediainfo\file__analyze_buffer_minimizesize.cpp 1 CLI
My system : win7/VS2008
Solution 1: Locate *.vcxproj file in your solution, open in a text editor and search for 'DebugInformationFormat' and set it to 'OldStyle'.  Reload your project and build. If you have multiple projects in your solution, this change needed for all the *.vcxproj files.
< DebugInformationFormat>OldStyle< /DebugInformationFormat>
Solution 2: From Visual Studio, on every project in your solution right click and open Properties. Expand 'Configuration Properties' > 'C/C++' > 'General'. Change the 'Debug Information Format' to 'C7 compatible (/Z7)'. Then build your solution.
This worked for me. (YMMV = Your mileage may vary:)
I've seen the same behaviour when converting a VS2003.Net solution to run on later IDEs. My guess is that your solution contains multiple projects which point to the same intermediate directory. In VS2005 and later, projects that don't depend on each other can be built in parallel so that if the same working dir is used, you can get file conflicts like this.
Check this as follows. In Solution Explorer, right click on one of the failing projects and select Properties. In Configuration Properties -> General section, make sure that every project has a different 'Intermediate Directory'. Try your build again using 'Rebuild Solution' to clean everything out.
Most of the times when I get "C2471: cannot update program database" it's because the PDB file is locked for some reason. Usually in my case that turns out to be because I have the program running in some other window, which loads the PDB file in to memory.
When that's not the reason, I find doing a rebuild-all magically fixes the problem.
I've encountered the same type of error myself with no end of frustration.
I finally fixed it by applying the Microsoft hot fix found in this knowledge base article: http://archive.msdn.microsoft.com/KB946040
This worked for me.
Kill mspdbsrv.exe and reload Visual C++
MSDN
You can delete the *.obj file and rebuild the solution again, This problem might solve. Below link might be helpful for you-
https://social.msdn.microsoft.com/Forums/vstudio/en-US/0ceac3c6-62f6-4fdf-82e1-d41e1b4fcd20/vs2008-c2471-cannot-update-program-database?forum=vclanguage

VC2008 compiler errors opening sbr files (C2418 C1903 C2471)

EDIT: See my answer below for the hotfix.
ORIGINAL QUESTION:
In setting up for our boat-programming adventure I have to set up source control and fix project files for a team to use them. (the project was previously only being worked on by one person who took shortcuts with setting up the project includes, etc)
I am fixing those SLN and Proj files. When trying to do a build on an external USB drive (I have not tried it on the primary hard drive) I am getting odd errors (lots of them for various files):
fatal error C1083: Cannot open
compiler generated file:
'.\Debug\.sbr': Permission
denied
These files are referenced in the vcproj file with relative paths in double quotes:
RelativePath="..\..\Source\.cpp"
I get the same errors form within a sln file in the IDE or if I call msbuild with the sln file.
The files are kind of "shared" for a few sln files (projects).
The person who originally created the SLN files is not known for being a wizard at configuring MSDev or making things work for teams.
Is this an issue with the way the source files are referenced? Any suggestions on how to fix these?
This URL does not seem to have helpful information:
Fatal Error C1083 on MSDN
Note - there were/are still hardcoded paths in the proj file, but i don;t see them for these files. They were mostly for the include and lib dirs. I think I removed them all.
I also get these errors:
..\..\Source\.cpp : error C2471:
cannot update program database '\debug\vc90.pdb'
..\..\Source\.cpp(336) : fatal
error C1903: unable to recover from
previous error(s); stopping
compilation
..\..\Source\.cpp(336) : error
C2418: cannot delete browser file:
.\Debug\.sbr
Title: You may receive a "PRJ0008" or "C2471" or "C1083" or "D8022" or "LNK1103" or similar error message when you try to build a solution in Visual C++
Symptoms:
D8022 : Cannot open 'RSP00000215921192.rsp'
PRJ0008 : Could not delete file 'vc90.idb'.
C1083 : Cannot open program database file 'vc90.pdb'
C2471 : Cannot update program database 'vc90.pdb'
LNK1103 : debugging information corrupt.
Cause:
This problem occurs when all of the following conditions are true:
You have a solution with more than one project in it.
Two or more of the projects are not dependent on each other.
You have parallel builds enabled. (Tools -> Options: Projects and Solutions, Build and Run: "maximum number of parallel project builds" is set to a value greater than 1)
You are building on a system with multiple CPUs (cores).
Two or more of the non-dependent projects are configured to use the same Intermediate and/or Output directory.
A specific race condition in mspdbsrv.exe remains uncorrected.
Resolution:
To resolve the problem do one or more of the following:
Reconfigure the non-dependent projects to specify an Intermediate and Output directory that is different from one another, e.g. Output Directory = "$(SolutionDir)$(ProjectName)\$(ConfigurationName)", Intermediate Directory = "$(OutDir)".
Adjust your solution's project dependencies (Project -> Project Dependencies...) so that each is dependent on another.
Disable parallel builds.
Add the "/onecpu" boot option to your boot.ini file.
Change you BIOS settings to enable/use only one CPU.
File a problem report with Microsoft Technical Support and keep bugging the crap out of them until they eventually fix mspdbsrv.
Status:
The problem is a combination of both a user project configuration error as well as a race condition in Microsoft's "mspdbsrv.exe" utility that does not properly handle more than one thread calling it at the same time for the same file resulting in the file's HANDLE being left open.
Additionally Visual Studio itself and/or its build system (VCBUILD and/or MSBUILD) (or all three!) should be made smart enough to detect and alert the user of such user errors so that corrective action can be taken.
This problem has been around for a LOOOOOONG time.
Applies to:
Microsoft Visual C++ 2005
Microsoft Visual C++ 2008
Others?
Respectfully submitted:
"Fish" (David B. Trout)
fish#infidels.org
p.s:
You're welcome. :)
Hmmm.
Perhaps:
http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/0ceac3c6-62f6-4fdf-82e1-d41e1b4fcd20/
there is a hotfix from MS
http://code.msdn.microsoft.com/KB946040
http://support.microsoft.com/kb/946040
That might be my problem. I think it might only be on one machine I have.
EDIT:
I downloaded and ran the hotfix installer. It seems to have fixed it.
I get this same error when I physically remove a file from disk, but leave it in VS. In VS2005 it would give a much better : fatal error file not found. I think this is a bug in VS2008. The hotfix mentioned above didn't help me.
In my case it was my virus package (Trend Micro) causing all the problems. I added my Dev folders to the Ignore/White lists to solve the problem
delete your debug folder and build your project agian.
Occastionally my Visual Studio will suddenly decide something like this. I have found it maybe help to toggle to release, do a full rebuild, then toggle back to debug.

VS2008 win32 project defaults - remove default precompiled headers

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.