c++ - 使用/GL 时向后兼容性中断

标签 c++ visual-studio

为了构建适用于 ARM64 设备的应用程序,我们将 VS 2017 15.5.7 升级到 15.9.6 版本。发布之后,使用/GL 标志构建的库 (15.9.6) 现在在测试应用程序(基于 15.5.7 构建)使用时抛出“无法识别的标志”错误,如下所示:

1>LINK : fatal error C1007: unrecognized flag '-Ot' in 'p2'
1>LINK : fatal error LNK1257: code generation failed

一旦在项目设置中禁用“全程序优化 (/GL)”,客户端构建就会通过。

谁能检查从 15.5.7 版本到现在抛出这个链接错误有什么变化? 还有什么是最佳优化的建议项目设置。

最佳答案

当您说使用此选项时向后兼容性被破坏时,您是对的。

Officially :

Whole program optimization allows the compiler to perform optimizations with information on all modules in the program. Without whole program optimization, optimizations are performed on a per module (compiland) basis.

而且,仍然是正式的,尽管它被提到是 between Visual Studio 2015 and Visual Studio 2017 :

Binary compatibility is not guaranteed in these cases:

  1. When static libraries or object files are compiled with the /GL compiler switch.
  2. When consuming libraries built with a toolset whose version is greater than the toolset used to compile and link the application. For example, a program that is compiled and linked with compiler version 19.12 can consume libraries that are compiled with 19.0 up through 19.12. Also, binary compatibility only exists between Visual Studio 2015 and Visual Studio 2017; linking 19.x programs with libraries produced by Visual Studio 2013 or earlier is not supported.

但非正式地,我可以这样说:

使用此编译器选项,如果您的依赖项之一是使用不同的编译器更新构建的(即使是一些较小的更新),链接几乎肯定会失败。

事实上,/GL 编译器选项对于 DLL 和 EXE 之间的向后兼容性非常严格,我们决定不再在我们公司使用它。

我们有很多 DLL,可执行文件构建在不同的项目上。

为了简短起见,在调试时,我们有时需要使用较新的编译器构建 exe,同时使用使用较旧的编译器编译的库

这个标志阻止了这样做。

可能对他人有帮助的解决方案:

  • 使用不带标志的旧编译器重建旧库
  • 使用新编译器重建旧库,同时保留标志(这意味着在出现新编译器时始终重建它们)
  • 使用旧编译器重建新的可执行文件(这意味着没有编译器更新)

关于c++ - 使用/GL 时向后兼容性中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54646695/

相关文章:

c++ - 尝试从 Visual Studios C++ 中的加密字符串输出解密字符串时出现逻辑错误

c - 查找文件操作的 CPU 使用率

C++:cin.getline - 没有重载函数的实例

C++ 相互依赖的类

c++ - 具有多个网络接口(interface)的计算机上的 gethostname

c++ - 用于 qtabbar 的 qt 自定义 qstyle

c# - 使用 Visual Studio Team Services (VSTS) 运行带有 SSL 错误的 Web/负载测试

c++ - 没有运算符 "=="处理这些操作数

c++ - 如何在 C++ 中构建执行异步后台任务的对象

.net - NuGet "TargetFramework"缺少 .Net 引用编译错误...如何修复?