Search code examples
visual-c++visual-studio-2015

VC compiler (Visual Studio 2015) can not link big (>2G) static lib file


Visual Studio 2015 can not link bigger than 2G static library.

The error is:

Can not find *.lib file.

My question is: Is it designed to? If so,why?


Solution

  • The 32-bit tools can only use 2 GB of virtual address space (although they are /LARGEADDRESSAWARE so technically on the 64-bit OS they can get 3 GB of virtual space). As such, the linker is likely just exhausting virtual address space on such a large library.

    The solution is to use the x64 native tools instead of the 32-bit ones.

    Either set an environment variable:

    set PreferredToolArchitecture=x64
    

    Or edit your vcxproj to add the following to your project file right after <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

    <PropertyGroup>
        <PreferredToolArchitecture>x64</PreferredTool‌​Architecture>
    </Prope‌​rtyGroup>
    

    See Sponsored Feature: RAM, VRAM, and More RAM: 64-Bit Gaming Is Here for the details on virtual address space limits in 32-bit vs. 64-bit apps.