Reputation: 22265
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?
Upvotes: 1
Views: 1396
Reputation: 37549
Go to C / C++ -> Code Generation. Set Runtime library
to Multi-threaded /MT
instead of Multi-threaded Dll /MD
Upvotes: 1