How to compile code for Windows XP in Visual Studio 2017 - c++

I was trying to compile a basic hello world program for Windows XP in Visual Studio 2017 on Windows 10. But it was giving some errors as showing in the image.
I already tried the steps mentioned in other Stack Overflow posts on this question, and changed the Platform tools "Visual Studio 2017 - Windows XP (v141_xp)" .
#include<iostream>
using namespace std;
int main() {
cout << "Hello world\n";
}
1>------ Build started: Project: WindowsProject1, Configuration: Debug Win32 ------
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Platforms\Win32\PlatformToolsets\v141_xp\Toolset.targets(39,5): warning MSB8051: Support for targeting Windows XP is deprecated and will not be present in future releases of Visual Studio. Please see https://go.microsoft.com/fwlink/?linkid=2023588 for more information.
1>stdafx.cpp
1>c:\program files (x86)\microsoft sdks\windows\v7.1a\include\objbase.h(239): error C2760: syntax error: unexpected token 'identifier', expected 'type specifier'
1>c:\program files (x86)\microsoft sdks\windows\v7.1a\include\gdiplusheaders.h(891): error C4596: 'EmfToWmfBits': illegal qualified name in member declaration
1>c:\program files (x86)\microsoft sdks\windows\v7.1a\include\gdiplusstringformat.h(220): error C4596: 'GetTrimming': illegal qualified name in member declaration
1>Done building project "WindowsProject1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

What you have encountered here are issues in the header files for the XP-Compatible SDK. The problem is actually quite arcane but, fortunately, relatively easy to deal with: you simply need to 'relax' the strictness of conformity checks the compiler uses...
To do this, right-click on your project in the Solution Explorer and select "Properties." On the invoked property-page, select the "C/C++" tab, and then the "Language" sub-tab. In the page then displayed, make sure you select "Conformance Mode" to "No". That should fix the issues.
Feel free to ask for further clarification and/or explanation.

You didn't say what template you started with, but I suspect that you have Conformance Mode (/permissive-) enabled. Go to Project -> Properties -> C/C++ -> Language and set Conformance Mode to "No".
The old Windows 7.1a SDK used to support Windows XP was never updated to be conformant with /permissive-.

Related

Cannot build console application with Microsoft Visual Studio 2019

I just installed the community version of VS 2019. I selected to build a console application that it created for me ("hello world" program). The file created is called ConsoleApplication1.cpp. I went to the build menu, selected build, and get the following error:
1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(441,5): warning MSB8003: The WindowsSDKDir property is not defined. Some build tools may not be found.
1>ConsoleApplication1.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\yvals.h(12,10): fatal error C1083: Cannot open include file: 'crtdbg.h': No such file or directory
1>Done building project "ConsoleApplication1.vcxproj" -- FAILED.
I tried to follow directions listed elsewhere on stackexchange. When I select "Project -> Properties" the Windows SDK field is blank. A value I typed in from the other StackExchange message creates an error that that version of the SDK cannot be found. So I deleted the version of the SDK and made it blank again. I also tried using "10.0" Here is where I received the advice:
Visual Studio 2017 errors on standard headers
Perhaps I did not install all the needed components. I recently checked off: "Windows Universal CRT SDK" (as per the instructions), but the build still fails. The warning is interesting. I looked that up also but have not found a solution that works. My "Platform Toolset" is Visual Studio 2019 (v142).
What might still be missing to build a console application? Thank you. I am working on Windows 7.

WinRT auto generated template compiling error in Visual Studio 2017

I am new to c++/WinRT. I am trying to create a new blank project under c++/WinRT using Visual Studio Pro 2017. But it gives some compiling error:
1>------ Build started: Project: BlankApp2, Configuration: Debug Win32 ------
1>Windows.AI.MachineLearning.MachineLearningContract.winmd
1>C:\Program Files (x86)\Windows Kits\10\References\10.0.17763.0\Windows.AI.MachineLearning.MachineLearningContract\1.0.0.0\Windows.AI.MachineLearning.MachineLearningContract.winmd : warning C4335: Mac file format detected: please convert the source file to either DOS or UNIX format
1>C:\Program Files (x86)\Windows Kits\10\References\10.0.17763.0\Windows.AI.MachineLearning.MachineLearningContract\1.0.0.0\Windows.AI.MachineLearning.MachineLearningContract.winmd(1): fatal error C1004: unexpected end-of-file found
1>midlrt : command line error MIDL1003: error returned by the C preprocessor (2)
1>Done building project "BlankApp2.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I updated my Visual Studio 2017 to the latest version. I also used the latest WinRT. I could build a console application using the code in Kenny Kerr's command window sample code. But couldn't build the blank application created by the Visual Studio 2017 wizard. Any help is greatly appreciated.

How to build a non-MFC C++ project with static linking to VC run-time libraries?

I know that for an MFC project built with Visual Studio, one can go to the project properties and then Configuration Properties -> General -> use of MFC and change it to Use MFC in a static library:
This works if the resulting build has to run in earlier versions of Windows without the need to install MFC or VC run-time DLLs. The resulting build will use DLLs that are already present in every installation of Windows since Windows 7 and up. (Possibly even down to Windows XP.)
Now if I create a non-MFC project, say a test C++ console application, the setting to use MFC is configured as "Use standard Windows Libraries":
But if I run the resulting binary file, say on a fresh install of Windows 7, I get this error:
So having dug around the settings, I couldn't find any way to compile it with static linking to all those newer versions of VC RT libraries. Is it there and I just don't see it?
PS. Having dug in further, I found out that I can change the "Platform Toolset" to Visual Studio 2017 - Windows XP (v141_xp), assuming that it will make it backwards compatible with Windows XP and up:
But then if I compile it, I'm getting these errors:
1>c:\program files (x86)\microsoft sdks\windows\v7.1a\include\objbase.h(239): error C2760: syntax error: unexpected token 'identifier', expected 'type specifier'
1>c:\program files (x86)\microsoft sdks\windows\v7.1a\include\dbghelp.h(1540): warning C4091: 'typedef ': ignored on left of '' when no variable is declared
1>c:\program files (x86)\microsoft sdks\windows\v7.1a\include\dbghelp.h(3056): warning C4091: 'typedef ': ignored on left of '' when no variable is declared
In this part of ObjBase.h file which has nothing to do with my test C++ console project that I just created from a Visual Studio template:
So my question is -- can I build a non-MFC C++ project that can run on older versions of Windows without the need to install VC Runtime or any other additional libraries?
Go to C / C++ -> Code Generation. Set Runtime library to Multi-threaded /MT instead of Multi-threaded Dll /MD

VC2010-SP1 Win7 32-bit - error C2338: CVarTypeInfo< char > cannot be compiled with /J or _CHAR_UNSIGNED flag enabled

I am getting following error on VC2010-SP1 Win7 32-bit. I tried for HotFix but it is no longer available here https://support.microsoft.com/en-us/kb/982517. Can anyone help? Thanks
ClCompile:
stdafx.cpp
C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlcomcli.h(1751): error C2338: CVarTypeInfo< char > cannot be compiled with /J or _CHAR_UNSIGNED flag enabled
C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlcomcli.h(1774): error C2338: CVarTypeInfo< char* > cannot be compiled with /J or _CHAR_UNSIGNED flag enabled
c:\Program Files\Microsoft SDKs\Windows\v7.0A\include\odbcss.h(430): error C2371: 'WCHAR' : redefinition; different basic types
c:\Program Files\Microsoft SDKs\Windows\v7.0A\include\winnt.h(344) : see declaration of 'WCHAR'
Build FAILED.
I tried for HotFix but it is no longer available here https://support.microsoft.com/en-us/kb/982517.
It's still available, but listed as requiring a support call (as many KBs do by default). You can however ask for a download link by email.
Since you run SP1 of VS2010, KB 982517 points to KB 2545588 for the fix. Following How can you download a hotfix without contacting Microsoft? which still works nowadays, click...
http://support.microsoft.com/hotfix/KBHotfix.aspx?kbnum=2545588&kbln=en-us
...accept the terms, and provide a valid email where you'll receive the download link. Be prepared for a massive download to the tune of 270+ MB. If the hotfix doesn't fix it, or breaks anything else, don't expect much support from MS (since you just agreed to their terms in a previous step ;-)).

Missing C++ Windows Runtime Component template

I'm trying to follow Consuming a C++ library project from a Windows Phone Store app. At the first step, the article instructs us:
So, the first step is going to be to create the C++ WinRT component. You can do this by adding a new project to the solution and selecting the appropriate project type as demonstrated in Figure 2. For the purposes of this example, the project type will be “Windows Runtime Component (Windows Phone) – Visual C++” (highlighted in green) as the application calling it is a Windows Phone Store app.
The problem I am having is I don't have the C++ Windows Runtime Component template installed. And its not available online, either:
I have Visual Studio Ultimate 2012, and I have the Windows Phone SDK installed along with the Windows Phone 8.0 kit. The article does not detail a Visual Studio version, but according to the Microsoft Dev Center we need Visual Studio 2012 and above for these apps.
Where, exactly, does one find the C++ Windows Runtime Component template?
The underlying problem I am trying to solve is the missing declaration for HANDLE, VOID, etc. It appears they are not included with <windows.h>. So I'm trying to duplicate a simple "Hello World" project to see what Microsoft includes in their sample projects.
cl.exe /nologo /W4 /D_MBCS /Zi /TP /EHsc /MD /DWINAPI_FAMILY=WINAPI_FAMI
LY_PHONE_APP /AI"C:\Program Files (x86)\Windows Phone Kits\8.0\Windows Metadata"
/c test.cpp
test.cpp
...
C:\Program Files (x86)\Windows Kits\8.0\include\um\minwinbase.h(46) : error C214
6: syntax error : missing ';' before identifier 'nLength'
C:\Program Files (x86)\Windows Kits\8.0\include\um\minwinbase.h(46) : error C443
0: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Windows Kits\8.0\include\um\minwinbase.h(47) : error C214
6: syntax error : missing ';' before identifier 'lpSecurityDescriptor'
...
But please don't focus on this problem; focus on the missing Visual Studio templates so I can fix future problems, too.