VS2017和VS2015之间的二进制兼容性
此SO帖子: Visual-C ++-2017二进制文件是否与VC ++-2015兼容?明确表示VS 2017与VS 2015具有二进制兼容性.甚至看起来像官方位置.
This SO post: Is Visual-C++-2017 binary compatible with VC++-2015? clearly says that VS 2017 is binary compatible with VS 2015. It even looks like the official position.
我的问题是,过去我清楚地记得每次尝试在使用以下命令编译的静态库中进行链接时都遇到链接器错误(我不记得具体的错误集).将MSVC的另一个版本转换为使用新版本的MSVC构建的EXE.
My question is, in the past, I distinctly remember running into linker errors (I do not recall the specific set of errors) every time I try to link in a static library that was compiled with a different version of MSVC into an EXE that is being built with a newer version of MSVC.
但是,二进制(in)兼容性听起来像是在运行时间 而不是链接时间会在您的脸上炸毁的东西.
Yet, binary (in)compatibility sounds like something that will blow up in your face at runtime, not link time.
有人可以告诉我,以前版本的MSVC是否确实因版本不匹配而产生了生产者链接器错误?如何完成的?
Can someone tell me if previous versions of MSVC did indeed producer linker errors on version mismatches? How was this accomplished?
这对打开WPO/LTCG生成的静态库有何影响?我相信它们会产生中间目标文件(与COFF相对),并且Microsoft不能保证这些中间文件的格式在编译器的不同版本之间保持停滞.
How does this affect static libraries built with WPO/LTCG turned on? I believe these produce intermediate object files (as opposed to COFF) and Microsoft did not guarantee the format of these intermediate files to remain stagnant across different versions of the compiler.
正如我在链接问题上回答的那样,VS 2015中的v140工具集和VS 2017中的v141工具集是二进制兼容的.由于v140的所有更新(例如VS 2015 Update 1、2、3)都属于同一家族,因此v141的创建属于同一家族"的成员.这是一个有意的设计决策,可帮助开发人员迁移到VS的新版本,而不必担心必须对其源代码进行更改.
As I answered on the linked question, the v140 toolset in VS 2015 and the v141 toolset in VS 2017 are binary compatible. v141 was built as a member of the same "family" as all the updates to v140 (e.g., VS 2015 Update 1, 2, 3) were all in the same family. This was an intentional design decision that helps developers to move to a new version of VS without worrying about having to make changes in their source code.
VS 2017可以支持多个工具集.下一个工具集将与v140/v141不二进制兼容.但是,在移动代码以使其与下一个工具集中的新C ++功能兼容时,您仍然可以安装v141.
VS 2017 can support multiple toolsets. The next toolset will not be binary compatible with v140/v141. But you'll still be able to install v141 as you move your code to be compatible with the new C++ features in the next toolset.
请注意,我们从未支持跨主要版本的二进制兼容性.无论WPO/LTCG/etc如何,都无法链接使用v140构建的二进制文件和使用v130构建的二进制文件.是的,它通常可以正常工作-我们会尽力减少库中的重大更改,因此在某些情况下,跨主要版本链接某些代码不会遇到任何错误.但是最终您会遇到一些变化,并且会看到错误.
Note that we never have supported binary compatibility across major versions. You can't link a binary built with v140 and a binary built with v130, regardless of WPO/LTCG/etc. Yes, it often works--we try to minimize breaking changes in our libraries so often it is the case that linking some code across major versions doesn't hit any errors. But eventually you'll run into something that changed and you'll see an error.
关于是否看到链接错误或运行时错误,取决于您调用的不兼容的库API.如果API的导出形状发生了变化(函数名称,参数数量),则链接程序将找不到它.如果形状相同但行为已更改,则可能会导致运行时失败.
As to whether you see a link error or a runtime error, that depends on the incompatible library API that you called. If the exported shape of the API changed--the name of the function, the number of parameters--then the linker will fail to find it. If the shape is the same but the behavior has changed, you can end up with a runtime failure.
-MSVC工具Andrew Pardoe
--Andrew Pardoe, MSVC tools