I am building some Visual C++ DLL and EXE projects with Visual Studio 2012. When building with the default platform toolset v110 the build is successful, but when building with the Windows XP compatible platform toolset v110_xp it fails with the following linker error in each project:
LINK : fatal error LNK1104: cannot open file ',5.01'
Note that if I change 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 some *.cpp file defining int main() {return 6;}
. It will build successfully until you change the platform toolset from v110 to v110_xp.
Why does this happen and how can I build these projects successfully with Windows XP compatibility?
In the project properties, under Linker -> System, make sure that you set the SubSystem property (either to Console for console applications, or to Windows for DLLs and non-console applications).
If you use common property sheets (*.props) to set project properties across all of your projects, you can add something like this to make sure that SubSystem is assigned a valid value if the project doesn't specify one 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 does this happen?
Choosing the v110_xp platform toolset automatically sets the Minimum Required Version linker setting to 5.01 or 5.02, because this is the version of 32-bit and 64-bit Windows XP, respectively.
When the the Minimum Required Version property is set, regardless of whether SubSystem is also set, Visual Studio tries to add both properties to the linker's command line arguments. This results in ,5.01
when SubSystem is not set (instead of the intended /SUBSYSTEM:CONSOLE,5.01
), and the linker understands this as trying to specify a file named ",5.01".
The latter is a bug in Visual Studio (not directly related to v110_xp). When Minimum Required Version is set and SubSystem isn't, VS should either ignore Minimum Required Version or issue a warning, but it shouldn't send malformed arguments to the linker.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With