在使用不同版本的visual studio的静态库中内部使用STL

在使用不同版本的visual studio的静态库中内部使用STL

问题描述:

我试图链接我的应用程序与静态库建立在不同版本的Visual Studio(我使用VS2010和lib是用VS2008构建)。静态库在内部使用STL,我得到一些basic_string方法无法找到的链接器错误。

I'm trying to link my application with a static library built in a different version of Visual Studio (I'm using VS2010 and the lib is built with VS2008). The static lib uses STL internally and I'm getting linker errors that some basic_string methods cannot be found.

我理解如果静态库在其公共接口使用STL,这是不可能的,因为STL对象是二进制不兼容的。但事实并非如此。没有从我调用的lib的方法使用STL和我没有传递STL对象到lib。但内部静态库在它自己的函数中使用STL。

I understand that if the static lib uses STL in its public interface then this is impossible, since the STL objects are binarily incompatible. But this is not the case. None of the methods from the lib that I am calling use STL and I am passing no STL objects to the lib. But internally the static lib uses STL in it's own functions.

看起来库没有编译STL代码,链接器试图将STL链接到内部方法。我的问题是有什么办法编译静态库静态链接到STL并包括所有的代码里面?

It looks like the library does not have the STL code compiled into it, and the linker is trying to link the STL into the internal methods. My question is is there any way to compile the static lib to statically link against the STL and include all the code inside of it?

我应该提到,我自己的应用程序使用STL。但是似乎两个版本都可以编译,只要它们从不传递给对方。

I should mention that my own application also uses STL. But it seems that both versions could be compiled in provided that they are never passed to each other.

静态库,并且此库依赖于标准C ++库的版本 X ,则您的应用程序需要与版本 X

If you are linking to a static library, and this library is dependent on the version X of the standard C++ library, then your application needs to be linked with version X, in addition to version Y you may be using in your application.

除了版本 Y ,您可能会在您的应用程式中使用和版本 Y 将会是相同的,你最终会出现一个链接器错误。

Since several exported symbol names of both, version X and version Y of the standard library will be the same, you end up with a linker error.

-party库中的DLL?这将解决问题。

Could you wrap the third-party library in a DLL? That would solve the issue.