gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 22:03:51 27 4
gpt4 key购买 nike

当 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com