静态链接到使用不同版本的C运行库构建的库,确定还是坏? [英] Statically linking against library built with different version of C Runtime Library, ok or bad?

查看:208
本文介绍了静态链接到使用不同版本的C运行库构建的库,确定还是坏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑这种情况:
应用程序链接到第三方库A。

Consider this scenario: An application links to 3rd party library A.

A使用MSVC 2008构建并静态链接/ MT)到C运行库v9.0。

A is built using MSVC 2008 and is statically linking (ie. built with /MT) to the C Runtime Library v9.0.

应用程序是使用MSVC 2005构建的,并静态链接到A和(使用/ MT)库v8.0。

The application is built using MSVC 2005 and is statically linking to A and (using /MT) to the C Runtime Library v8.0.

我可以看到麻烦的 - 例如如果类型在运行时库版本之间的头更改。

I can see trouble with this - for instance if types are changed in the headers between runtime library versions.

注意保持运行时库头文件在版本之间兼容,还是应该始终确保所有静态链接库都链接到同一版本的运行时库? / p>

Is care taken to keep the runtime library headers compatible between versions, or should one always make sure all statically linked libraries are linking to the same version of the runtime library?

推荐答案

应该 不是问题。每个库链接到其自己的运行时,并且大多数函数独立于进程中的其他库。当库ABI被严重定义时,问题就出现了。如果任何种类的堆分配对象被分配在一个库中,跨越库边界传递并在另一个库中释放,则会出现问题,因为使用不同的堆管理器从用于分配的堆管理器释放一个块

It should not be a problem. Each library links to its own runtime and mostly functions independently from other libraries in the process. The problem comes about when the libraries ABI is badly defined. If any kind of heap allocated object is allocated in one library, passed across a library boundary and 'freed' in another library there are going to be problems as a different heap manager is being used to free a block from the heap manager used to allocate it.

任何类型的c运行时定义的结构,对象或实体不应跨越边界传递,其中可能使用不同的运行时版本: - FILE *从一个库中获取例如对不同的库链接到不同的运行时没有意义。

Any kind of c-runtime defined struct, object or entity should not be passed accross boundries where a different runtime version might be being used :- FILE*'s obtained from one library for example will have no meaning to a different library linked against a different runtime.

只要库API只使用原始类型,并且不尝试在指针中传递free(),或者传递指针到内部malloc()内存,他们希望应用程序(或另一个库)释放()你应该确定。

As long as the library API's use only raw types, and do not try to free() passed in pointers, or pass out pointers to internally malloc()'d memory that they expect the application (or another library) to free() you should be ok.

如果c运行时混合,但是你必须记住libs和动态库(.so / .dll / .dylib)传统上是开发的在各种语言中:允许以asm,c,c ++,fortran,pascal等编写的代码通过有效的CPU高效的二进制接口进行转换。

Its easy to fall for the FUD that "anything can go wrong" if c-runtimes are mixed, but you have to remember that libs, and dynamic libraries (.so / .dll / .dylib) have traditionally been developed in a wide variety of languages: allowing code written in asm, c, c++, fortran, pascal etc to comminicate via an effective CPU efficient binary interface.

为什么突然恐慌C正在链接到C?

Why suddenly panic when C is being linked to C?

这篇关于静态链接到使用不同版本的C运行库构建的库,确定还是坏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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