VS2010和VS2012之间的二进制C ++库兼容性? [英] Binary C++ library compatibility between VS2010 and VS2012?

查看:177
本文介绍了VS2010和VS2012之间的二进制C ++库兼容性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对VS2010和VS2012之间的编译库的二进制兼容性感到困惑。我想迁移到VS2012,但是许多封闭源二进制只有SDK只适用于VS2010,例如SDK用于接口硬件设备。

I am confused about the binary compatibility of compiled libraries between VS2010 and VS2012. I would like to migrate to VS2012, however many closed-source binary-only SDKs are only out for VS2010, for example SDKs for interfacing hardware devices.

传统上,因为我知道Visual Studio是非常挑剔的编译器版本,在VS2010你不能链接到为VS2008编译的库。

Traditionally, as far as I know Visual Studio was extremely picky about compiler versions, and in VS2010 you could not link to libraries which have been compiled for VS2008.

现在我困惑的原因是,我正在迁移到VS2012,我已经尝试了几个项目,为我最大的惊喜,他们中的许多人工作的交叉版本没有问题。

The reason I'm confused now, is that I'm in the process of migrating to VS2012, and I have tried a few projects, and for my biggest surprise, many of them work cross-versions with no problems.

注意:我不是在谈论v100模式,据我所知, VS2012 GUI VS2010编译引擎。

Note: I'm not talking about the v100 mode, which as far as I know is just a VS2012 GUI over the VS2010 compiling engine.

我在说VS2012中打开VS2010解决方案,点击更新,看看会发生什么。

I'm talking about opening a VS2010 solution in VS2012, click update, and seeing what happens.

当链接到一些更大的库,如boost,编译没有工作,因为有检查编译器版本,他们引发错误和中止编译。一些其他的库只是中断了缺少的函数。这是我期待的行为。

When linking to some bigger libraries, like boost, the compiling didn't work, as there are checks for compiler version and they raise an error and abort compilation. Some other libraries just abort at missing functions. This is the behaviour what I was expecting.

另一方面,许多库工作正常,没有错误或额外的警告。

On the other hand, many libraries work fine with no errors or additional warnings.

怎么可能? VS2012是否以特殊方式保持与VS2010库的二进制兼容性?它是否依赖于动态链接和静态链接?

How is it possible? Was VS2012 made in a special way to keep binary compatibility with VS2010 libraries? Does it depend on dynamic vs. static linking?

最重要的问题是:即使在编译时没有引发错误,我可以相信编译器在将VS2012项目链接到VS2010编译库时,是否会出现任何错误?

And the most important question: even though there is no error raised at compile time, can I trust the compiler that there won't be any bugs when linking a VS2012 project to VS2010 compiled libraries?

推荐答案

如何可能?

1)lib被编译为使用静态RTL,因此代码不会拉入第二个RTL DLL冲突。

1) the lib is compiled to use static RTL, so the code won't pull in a second RTL DLL that clashes.

2)代码只调用完全在头文件
中的函数(并使用结构等),因此不会导致链接器错误,或
调用仍存在于新RTL中的函数,因此不会导致链接器错误。

2) the code only calls functions (and uses structures, etc.) that is completely in the header files so doesn't cause a linker error, or calls functions that are still present in the new RTL so doesn't cause a linker error,

3)不调用任何具有已更改布局的结构,意义所以它不会崩溃。

3) doesn't call anything with structures that have changed layout or meaning so it doesn't crash.

#3是一个担心。您可以使用导入来查看它使用的是什么,并制作完整的列表,但没有关于哪些兼容的文档或保证。只是因为它似乎运行并不意味着它没有潜在的错误。

#3 is the one to worry about. You can use imports to see what it uses and make a complete list, but there is no documentation or guarantee as to which ones are compatible. Just because it seems to run doesn't mean it doesn't have a latent bug.

还有

4)驱动程序SDK或其他水平相当低的代码是为了避免完全使用标准库调用。

4) the driver SDK or other code that's fairly low level was written to avoid using standard library calls completely.

DLL可以被隔离并且具有它们自己的RTL并且不在不同的状态之间来回传递(比如存储器分配和释放)。内部COM服务器工作方式。 DLLs 一般来说,如果你仔细考虑你传递和返回的东西,以及你对指针等事情做了什么。 Crypto ++例如使用封装程序的内存例行程序初始化,并且不会从编译的RTL版本暴露malloc的内存。

also (not your situation I think) DLLs can be isolated and have their own RTL and not pass stuff back and forth (like memory allocation and freeing) between different regimes. In-proc COM servers work this way. DLLs can do this in general if you're careful about what you pass and return and what you do with things like pointers. Crypto++ for example is initialized with the memory routines from the enclosing program and doesn't expose malloc'ed memory from the RTL version it was compiled with.

这篇关于VS2010和VS2012之间的二进制C ++库兼容性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆