Linker error when using v110_xp: "cannot open file", 5.01 '"

I am creating several Visual C ++ DLL and EXE projects with Visual Studio 2012. When building using the standard toolkit of the v110 platform, the assembly was successful, but when creating using the toolkit of the v110_xp platform compatible with Windows XP, it does not cope with the following linker error in each project:

LINK: fatal error LNK1104: cannot open file ', 5.01'

Please note that if I changed the platform from Win32 to x64, the errors change to:

LINK: fatal error LNK1104: cannot open file ', 5.02'

This can be easily reproduced by creating a new EXE project from the "Empty project" template in Visual Studio and adding a * .cpp file that defines int main() {return 6;} . It will work successfully until you change the platform toolkit from v110 to v110_xp.

Why is this happening and how can I successfully create these projects with compatibility with Windows XP?

+7
visual-c ++ visual-studio-2012 linker-errors
source share
1 answer

In the project properties, under Linker → System, make sure that you set the SubSystem property (either in the console for console applications, or in Windows for DLL and non-console applications).

If you use common properties (* .props) to set project properties in all your projects, you can add something like this to make sure that the SubSystem is assigned a valid value if the project does not specify it explicitly.

 <?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemDefinitionGroup> <Link> <SubSystem Condition="'%(Link.SubSystem)'=='' Or '%(Link.SubSystem)'=='NotSet'">Windows</SubSystem> </Link> </ItemDefinitionGroup> </Project> 

Why is this happening?

  • The choice of platform tools v110_xp automatically sets the link for 5.01 or 5.02 for the parameter of the minimum required version, because it is the version of 32-bit and 64-bit Windows XP, respectively.

  • When the Minimum Required Version property is set, regardless of whether SubSystem is installed, Visual Studio tries to add both properties to the linker command line arguments. This results in ,5.01 , when the SubSystem is not installed (instead of the expected /SUBSYSTEM:CONSOLE,5.01 ), and the linker understands this as an attempt to specify a file named ", 5.01".

The latter is a bug in Visual Studio (not directly related to v110_xp). When the minimum required version is specified and the SubSystem is not, VS must either ignore the minimum required version or issue a warning, but must not send invalid arguments to the linker.

+17
source share

All Articles