Juicebox
Juicebox

Reputation: 442

Why can't the Visual Studio linker open a very big static library (>2.5GB)?

I've built a heavy template x64 debug static library with Visual Studio 2015 and it produces a .lib file which exceeds 2.5GB. The problem is that when I want to link it with my executables, I get this error:

LNK 1104 : cannot open 'my-lib.lib'

This lib exists for sure because I've tried to open it with dumpbin.exe to see what symbols cause the big size, but the funny part is that dumpbin itself produces the same error.

Is there a size limit for static libraries used with Visual Studio?

Upvotes: 4

Views: 1342

Answers (2)

TBBle
TBBle

Reputation: 1476

(Repeating my earlier comment as an answer, since it worked...)

Try the 64-bit toolchain. See How to make Visual Studio use the native amd64 toolchain for details of the PreferredToolArchitecture environment variable.

Similarly, for dumpbin, use the x64-native version of dumpbin.

Upvotes: 2

the_mandrill
the_mandrill

Reputation: 30842

As @TBBle suggests, try the 64-bit toolchain option first (this may be worth doing anyway, as you may get better performance with your larger libraries), but I reckon you will still run into problems with a .lib file over 2GB because I think that exceeds the Windows format limit (I've struggled to find a definitive answer to the maximum allowable size, but I've certainly run into problems as the size gets towards 2GB).

It's quite likely your only real solution is to split the .lib file up into smaller static libraries, or maybe go the other way and don't use the static library at all - just build all the cpp files straight into your project. It will depend on the structure of your project which is the easiest approach.

I've found a quick way of splitting a static library project is to copy the vcxproj and vcxproj.filters file, then in one version change the <ProjectGuid>, <RootNamespace> and <ProjectName> fields to new values, then load that project into your solution and delete half of the files in each of the two projects.

Upvotes: 2

Related Questions