Visual Studio C++ cannot open some headers I didn't deliberately include - c++

today I wanted to start learning C++.
However I keep getting these errors:
Cannot open source file "stdio.h"
Cannot open source file "tchar.h"
Cannot open source file "SDKDDKver.h"
However, I even get these in a default empty win32 console project.
Does anyone know how to fix this?
OS: windows 10
My default code looks like this:
// HelloWorld.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int main()
{
return 0;
}
The errors are:
Severity Code Description Project File Line Suppression State
Error (active) cannot open source file "stdio.h" HelloWorld c:\Users\HP\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\stdafx.h 10
Severity Code Description Project File Line Suppression State
Error (active) cannot open source file "tchar.h" HelloWorld c:\Users\HP\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\stdafx.h 11
Severity Code Description Project File Line Suppression State
Error (active) cannot open source file "SDKDDKVer.h" HelloWorld c:\Users\HP\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\targetver.h 8
Severity Code Description Project File Line Suppression State
Error (active) cannot open source file "stdio.h" HelloWorld c:\Users\HP\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\stdafx.h 10
In the OUTPUT window:
1>------ Build started: Project: HelloWorld, Configuration: Debug Win32 ------
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\Win32\PlatformToolsets\v140\Toolset.targets(34,5): error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution".
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
EDIT:
I believe I have C++ installed, cause first when I went to
file > new > project > Visual C++
It would only show me "Install ... for C++", So I installed one of the first options (don't remember which one it was) and after installing it allowed me to create projects.

Check your stdafx.h contents. Headers can be included transitively. In particular, the three ehaders you quote are in the VC++ stdafx.h for new projects. You can simply remove them if you're programming C++.
(It says something about Microsoft's struggle to choose between C and C++ : They don't support C99, but they default to a C header instead of C++. Not even <cstdio>. )

Related

Error: Cannot open include file: 'MQTTAsync.h': No such file or directory

OS -Windows 10 x64
Library mqtt
Microsoft Visual Studio Community 2017 Version 15.9.15
Programming Language - C++17
Installed paho-mqtt paho-mqttpp3 paho-mqttpp3[ssl] using vcpkg
I am creating a c++ program using mqtt.
But whenever I am using below given header
#include <mqtt/async_client.h>
It is giving following error
d:\vcpkg\installed\x64-windows\include\mqtt\async_client.h(27): fatal error C1083: Cannot open include file: 'MQTTAsync.h': No such file or directory
But MQTTAsync.h file is available on the given location
D:\vcpkg\installed\x64-windows\include\paho-mqtt
I had followed below link by creating new console project
https://github.com/Microsoft/vcpkg/issues/1848
Still issue is not getting resolved
Verify the correct name in your vcpkg-directory.
In my case that would be C:\Users\USERNAME\vcpkg\installed\x64-windows\include\paho-mqtt
Here you will see that the header file you are looking for is actually called MQTTAsync.h
To add it in your project you will have to change your inlcude to #include <paho-mqtt/MQTTAsync.h>

How to fix Cannot open source file: 'seal/util/config.h'

I am currently using VS studio 2019 and cloned from GIT MicrosoftSEAL using Visual Studio i am having problems making it run.
I already downloaded C++ packages along with SDK 10.0.16299.0 then retargetted the whole projects but still getting the 34 errors (1 E196 and 33 C0183) from a file called mscv.h which has the include line underlined
// Read in config.h
#include "seal/util/config.h"
Errors:
Error (active) E1696 cannot open source file "seal/util/config.h"
Error C1083 Cannot open include file: 'seal/util/config.h': No such file or directory

Cannot open file 'sfml-graphicsd.lib'

I have recently picked up the book Beginning C++ Game Programming. I am following the book as precise as I can. I am a Java dev with about 2 years experience who is looking to pick up C++. I thought it would be fun learning it while learning game programming.
So I am getting the error 1>LINK : fatal error LNK1104: cannot open file 'sfml-graphicsd.lib'. I have added the include to the file, I have added the additional include and libs in the C++, Linker and Debug project properties. I will include the code, there is nothing yet I just wanted to see the window that is being created but already getting compiler errors.
I have noticed that the actual file name is sfml-graphics-d.lib whereas the compiler seems to be trying to open sfml-graphicsd.lib. I have checked the version of SFML that I downloaded and it is Visual C++ 14 (2015) - 32-bit and I am compiling win32.
Code:
// Samurai.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <SFML\Graphics.hpp>
using namespace sf;
int main()
{
VideoMode vm(1920, 1080);
Window(vm, "Samurai", Style::Fullscreen);
return 0;
}
Output:
1>------ Build started: Project: Samurai, Configuration: Debug Win32 ------
1>LINK : fatal error LNK1104: cannot open file 'sfml-graphicsd.lib'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Please let me know if any further information is required.
Thank you all so much,
Owen
I found the error. It was a spelling mistake in the properties > debugs > linker > input there was no - in the dll filenames

How does visual studio (ms compiler) know it needs specific boost libraries

vs2015 community, x64, debug, boost 1.63
New Empty project
Properties->C++->General->Additional Include Directories add
"C:\Program Files\boost_1_63_0" Add new C++ file, Source.cpp:
#include "boost/make_shared.hpp"
#include "boost/thread.hpp"
void main(int argc, char **argv)
{
}
Build Solution
Result:
1>------ Build started: Project: boostLibTest, Configuration: Debug x64 ------
1> Source.cpp
1>LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc140-mt-gd-1_63.lib'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Where is that lib file getting added to the project? It's not boostLibTest.vcxproj, nor the command line for the compiler.
I wanted to write a static library that uses boost that I can access from another app that doesn't have/need boost, but this auto-include-boost-dependency prevents me from doing so.
There are #pragmas that MSVC supports that let a header file state "you need this library".
Boost is apparently using them.
Ideally, boost should only include them in header files that are not "header only". The granularity may not be perfect. But if you only need some enum values and other header-file only data from "boost/thread.hpp", check to see if they are included in a "header-file-only" header.

Building a C++ project in Visual Studio doesn't create any files

I recently decided to start learning Visual Studio so that it replaces my need for CodeBlocks and MinGW for C++ programming.
So, today I made a new Win32 C++ Console Application, wrote down this code in a new .cpp file
#include <iostream>
using namespace std;
int main()
{
int a;
cin >> a;
cout << a << endl;
return 0;
}
and compiled it. The log said
1>------ Build started: Project: CPP_CONSOLE_TEST, Configuration: Debug Win32 ------
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppBuild.targets(357,5): warning MSB8004: Output Directory does not end with a trailing slash. This build instance will add the slash as it is required to allow proper evaluation of the Output Directory.
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
and I though my code was compiled and my .exe was created.
Then, upon trying to debug my program, Visual Studio said:
Unable to start program 'C:\Users\XYZ\Documents\Visual Studio 2013\Projects\CPP_CONSOLE_TEST\Debug\CPP_CONSOLE_TEST.exe'. The system cannot find the file specified.
I then opened the Debug folder of the project and it was completely empty...
I've been searching around Google for some time and I even tried to "Repair" my Visual Studio build with no results. Any help?
Quick edit: Just tried compiling a C# app, just to see if the IDE itself was the problem. It compiled and ran just fine, so it's some issue with the Visual C++ compiler and its settings...
Turns out I hadn't added the source file to the Project... :|
Visual Studio, has its own vision of c++ projects. By default, it needs a #include "stdafx.h" on top of your cpp file, with the associated stdafx.h and stdafx.cpp files.
Then, in a c++ visual studio project, the real definition of the main function is int _tmain(int argc, _TCHAR* argv[]). But it should work with your definition.
Why don't you try to use Serge Rogatch's solution?
There is a bug in Visual Studio which leads to problems when project has long path.