Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 658
Yodan Tauber Avatar asked Jun 03 '14 09:06

Yodan Tauber


1 Answers

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?

  1. 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.

  2. 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.

like image 151
Yodan Tauber Avatar answered Oct 08 '22 04:10

Yodan Tauber