c++ - Visual Studio 2012 更新是否会破坏 C++ ABI?

标签 c++ visual-studio-2012 abi

当 Microsoft 在 2012 年 9 月最初发布 Visual Studio 2012 时,他们宣布了更定期为 Visual Studio 提供更新的计划。从那以后,他们发布了Visual Studio 2012 Update 1 (Visual Studio 2012.1) 2012 年 11 月和 Visual Studio 2012 Update 2 (Visual Studio 2012.2) 2013 年 4 月。

我的问题是:更新是否对 C++ ABI 进行了任何更改(关于初始 VS2012 版本)?链接不同VS2012版本的.lib安全吗?

我在互联网上搜索了一段时间,没有找到任何来自微软的明确声明。一些 sources提到 C++ 代码生成中的一些错误已得到修复,但我认为这并不意味着 ABI 更改?

最佳答案

Visual C++ 的 STL 实现的主要作者 Stephan T. Lavavej 在此 Reddit thread 中阐述了规则。 :

Here are the precise rules:

If you include any C++ Standard Library headers, you have to play by its rules, and we intentionally break binary compatibility between major versions (but preserve it between hotfixes and service packs). Any representation changes (including but not limited to adding/removing data members) break binary compatibility, which is why this always happens and why we jealously guard this right.

[snip]

So, if you're playing by the STL's rules, you need to ensure the following:

  • All object files and static libraries linked into a single binary (EXE/DLL) must be compiled with the same major version. We added linker checks, so that mismatching VS 2010+ major versions will trigger hard errors at link time, but if VS 2008 or earlier is involved we can't help you (no time machines). Because the ODR applies here, you really should be using the same toolset (i.e. same service pack level) for all of the object files and static libraries. For example, we fixed a std::string memory leak between VS 2010 RTM and SP1, but if you mix RTM and SP1, the resulting binary may or may not be affected by the leak. (Additionally, you need to be using the same _ITERATOR_DEBUG_LEVEL and release/debug settings; we have linker checks for these now.)
  • If you have multiple binaries loaded into the same process, and they pass C++ Standard Library objects to each other, those binaries must be built with the same major version and _ITERATOR_DEBUG_LEVEL settings (release/debug should match too, I forget if you can get away with mismatch here). Importantly, we cannot detect violations of this rule, so it's up to you to follow it.
  • Multiple binaries whose interfaces are purely C or COM (or now WinRT) may internally use different major versions, because those things guarantee binary compatibility. If your interfaces involve the C++ Core Language (e.g. stuff with virtuals) but are extremely careful to never mention any C++ Standard Library types, then you are probably okay - the compiler really tries to avoid breaking binary compatibility.

Note, however, that when multiple binaries loaded into a single process are compiled with different major versions, you'll almost certainly end up with multiple CRTs loaded into your process, which is undesirable.

Bottom line - if you compile everything 100% consistently, you just don't have to worry about any of this stuff. Don't play mixing games if you can possibly avoid it.

关于c++ - Visual Studio 2012 更新是否会破坏 C++ ABI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15836087/

相关文章:

blockchain - abi.encodePacked(...) 和 sha256(..) 如何在 Solidity 中工作?

c++ - 如何用预制数据初始化指向指针的指针?

c++ - std::string 处理短字符串的性能

函数不接受 c++ 参数

visual-studio-2012 - 如何注册适合VS2012 Cassini和IIS7的HttpModule?

visual-studio-2012 - Visual Studio 11 (2012) beta 到 RC?

visual-studio - MSBuild 不包含 "VCTargetsPath"属性的值

c++ - 为什么我的 MFC 应用程序不能完全退出?

c - 被调用的函数在被调用后如何返回给调用者?

c++ - libstdc++ 的 make_shared 布局是否在 gcc 4.x 和 gcc 6.x 之间发生了变化?