Mixing Static Libraries of C Code built from different versions of Visual Studio 2002 and later

﹥>﹥吖頭↗ 提交于 2019-11-30 09:44:42

问题


I have a static linkable library of C and Fortran routines compiled and linked together using the Visual Studio 2002 C (v7.0) Compiler and the Intel Fortran 9.0.018 Compiler.

The C code in my library calls and links to the Microsoft C-RunTime (MSCRT) 2002 static libraries (single-threaded). I believe the actual version number of the 2002 CRT libraries is v7.0

I will refer to this static library as "vs2002if9.lib"

Can I statically link to my "vs2002if9.lib" safely using any later version of Visual Studio (2003, 2005 or 2008) without any worries about how the calling program behaves regarding the C runtime calls?

Or am I creating problems by mixing version of the CRT static libs?

What if I provide my "vs2002if9.lib" to 3rd party software developers? What requirements am I imposing on them?


回答1:


Mixing C runtimes hasn't worked for me in the past. The only manner in which I can see this working {maybe} is if you're completely isolating the use of the stack/heap within the boundaries of the statically linked C-Runtime [nothing crosses boundaries via parameters but then what value is your vs2009if9.lib providing].

As an example, if you're to be allocating a pointer [heap memory] within the application and passing this pointer to the library you provided, which heap manager should be used? The correct answer is the heap manager managing the pointer, but your library won't know about the other heap manager. It gets uglier if your library allocates memory for use by the application and it's the applications responsibility to free/delete using the provided pointer (bad design yes but still possible). Again, the wrong heap manager will be utilized.



来源:https://stackoverflow.com/questions/462768/mixing-static-libraries-of-c-code-built-from-different-versions-of-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!