windows 链接器内存不足 LNK1102
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/174013/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
linker out of memory LNK1102
提问by Vhaerun
My colleagues and I have tried to build a project containing several thousand classes , but we're getting a LNK1102 error ( Linker out of memory ) . I've seen several tips on the internet , such as increasing the virtual memory . We tried but this didn't help . We've also seen some as enabling different warning levels when compiling the code . A guy suggested enabling level 4 for warnings . How could that be done ? Are there other suggestions ?
我和我的同事试图构建一个包含数千个类的项目,但我们收到了 LNK1102 错误(链接器内存不足)。我在互联网上看到了一些技巧,例如增加虚拟内存。我们尝试过,但这没有帮助。我们还看到一些在编译代码时启用不同的警告级别。一个人建议启用 4 级警告。那怎么可能呢?还有其他建议吗?
回答by Gerrit
I just had the same problem when compiling plain C:
我在编译普通 C 时遇到了同样的问题:
"*LINK : fatal error LNK1102: out of memory*"
Solution for me was: delete all *.pdb (DEBUG) files around. After that, everything was linked without problems. So probably a pdb file was defect in my case - defect in a funny way to cause this linker error.
我的解决方案是:删除所有 *.pdb (DEBUG) 文件。在那之后,一切都没有问题地联系起来。因此,在我的情况下,pdb 文件可能存在缺陷 - 以一种有趣的方式缺陷导致此链接器错误。
回答by Peter Goras
Project (right click) → Properties → Configuration Properties → Linker → Optimization → References → change to Keep Unreferenced Data
项目(右键单击)→属性→配置属性→链接器→优化→引用→更改为保留未引用数据
Worked on my machine!
在我的机器上工作!
回答by ralphtheninja
I suspect that the linker also takes a lot of time to finish. Since you are saying there are thousands of c++ classes, my first thought was to check if there are many inlined class methods.
我怀疑链接器也需要很多时间才能完成。既然你说有成千上万的 c++ 类,我的第一个想法是检查是否有很多内联类方法。
Try this:
尝试这个:
Pick a bunch of classes that are used the most, make all inlined methods non-inline by moving them from the header file to the implementation file. I've experienced drastic changes in linking time. One project we had went from 15 minutes of pure linking to just 30 seconds. This should also affect the memory of the linking process.
选择一堆最常用的类,通过将所有内联方法从头文件移动到实现文件来使它们成为非内联方法。我经历了链接时间的巨大变化。我们的一个项目从 15 分钟的纯链接时间缩短到了 30 秒。这也应该影响链接过程的内存。
Good luck! //Magnus
祝你好运!//马格努斯
回答by HS.
If the project is too large, then split it up into several components.
如果项目太大,则将其拆分为多个组件。
This might also help with maintenance.
这也可能有助于维护。
回答by Jimoc
If you are running this on a windows machine, open up task manager while linking and go to the performance page. If you see the page file usage increasing until its full, then increase the size of it to at least double your ram. If the page file is not filling up before it throws the error, then ensure there is enough disk space on the machine.
如果您在 Windows 机器上运行它,请在链接时打开任务管理器并转到性能页面。如果您看到页面文件使用量不断增加直到满,则将其大小增加到至少两倍于您的内存。如果页面文件在引发错误之前没有填满,请确保机器上有足够的磁盘空间。
回答by loufor1
If using Visual C++ 6.0, avoid loading workspace from a "subst" drive or "network mapped" drive. Copying the project to "C:\temp\MyProject\" folder, and loading the workspace from this location, made the "LNK1102" error go away for me this time.
如果使用 Visual C++ 6.0,请避免从“subst”驱动器或“网络映射”驱动器加载工作区。将项目复制到“C:\temp\MyProject\”文件夹,并从此位置加载工作区,这一次使“LNK1102”错误消失了。
Hope it helps!
希望能帮助到你!
回答by Pablo H
I had this fatal error LNK1102: out of memory
error and solved it by using 64bits compiler and linker. You set an environment variable:
我遇到了这个fatal error LNK1102: out of memory
错误并通过使用 64 位编译器和链接器解决了它。你设置一个环境变量:
set PreferredToolArchitecture=x64
and then run Visual Studio.
然后运行 Visual Studio。
回答by Teivaz
The solution mentioned herea couple of times is to use the 64 bit host compiler tools.
这里多次提到的解决方案是使用 64 位主机编译器工具。
For a CMake-generated project this can be achieved by setting the variable CMAKE_GENERATOR_TOOLSET
to the value host=x64
, either in CMakeLists.txt
:
对于 CMake 生成的项目,这可以通过将变量设置CMAKE_GENERATOR_TOOLSET
为 value来实现host=x64
,无论是在CMakeLists.txt
:
set(CMAKE_GENERATOR_TOOLSET "host=x64")
or on the cmake command line add
或在 cmake 命令行添加
-T host=x64
Note: this setting only applicable to Visual Studio generators. For any other generators it will cause a fatal error.
注意:此设置仅适用于 Visual Studio 生成器。对于任何其他生成器,它将导致致命错误。
回答by MSalters
Run the 64 bits version of the Linker? Downside: you'll get a amd64 executable. (Unlike the 32->64 crosscompilation toolset, there is no 64->32 bit toolset)
运行 64 位版本的链接器?缺点:您将获得 amd64 可执行文件。(与 32->64 位交叉编译工具集不同,没有 64->32 位工具集)
回答by Wedge
Definitely monitor the actual memory usage through task manager while linking. Close other programs to increase your available physical memory and set your page file to 4092 mb in size, if possible.
链接时肯定会通过任务管理器监视实际内存使用情况。如果可能,关闭其他程序以增加可用物理内存并将页面文件的大小设置为 4092 mb。
Also, it might help to create a link repro. This will allow other people to try to reproduce your link issues on other machines.
此外,它可能有助于创建链接 repro。这将允许其他人尝试在其他机器上重现您的链接问题。