混合来自不同版本的Visual Studio的库时的运行时问题 [英] Runtime Issues While Mixing Libraries from Different Versions of Visual Studio

查看:106
本文介绍了混合来自不同版本的Visual Studio的库时的运行时问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行使用两个不同版本的Visual Studio构建的项目时,我遇到了意外的访问错误.我的一般配置如下:

I have encountered an unexpected Access Error while running a project I've built using two different versions of Visual Studio. My general configuration is as follows:

  • LibA是静态库,静态运行时链接,msvc 8.0
  • LibB是静态库,静态运行时链接,msvc 9.0
  • 我集成的目标项目是msvc 9.0 COM dll,它静态链接上述库

此项目已构建,但在运行时因某些STL代码中的访问冲突而崩溃.堆栈似乎表明在调用流插入运算符期间,我已经通过了两个版本(8和9)的标头.我意识到这是一个问题.

This project builds, but crashes up at runtime with an access violation in some STL code. The stack seems to indicate that I've passed through headers both versions (8 and 9) during a call into a stream insertion operator. I realize that this is a problem.

以某种方式,这个电话:

Somehow, this call:

ost << std::dec << port_; //(originating from an object in LibA)

...通过以下堆栈跟踪下降:

...descends through the following stack trace:

std::basic_ostream::operator<<(...) (ostream:283, msvc 8.0 version <-- expected, since LibA was built with this version)
std::num_put::put(...) (xlocnum:888, msvc 8.0 version <-- expected, since LibA was built with this version)
std::num_put::do_put(...) (xlocnum:1158, msvc 9.0 version!! !@#$!%! <-- not expected, since LibA was built with msvc 8.0)
std::ios_base::flags() (xiosbase:374, msvc 9.0 version <-- follows from above)

访问冲突发生在std :: ios_base :: flags()中.我怀疑这是由于调用堆栈中实现的混合(尽管我不确定).

The access violation happens in std::ios_base::flags(). I suspect it is due to the mix of implementations in the call stack (although I am not sure).

我的问题是

1.)这种访问冲突的可能原因是msvc标头实现的混合吗?
2.)有没有办法防止这些实现方式混淆?
3.)是否有更好的方法来配置这三个项目以进行集成(假设不希望从msvc 8.0中迁移LibA)?

1.) Is the likely cause of this access violation the mixing of msvc header implementations?
2.) Is there a way to prevent these implementations from mixing?
3.) Is there a better way to configure these three projects for integration (assuming moving LibA from msvc 8.0 is undesirable)?

我知道这个.在这里,我对这个特定的问题最感兴趣,是否有某种方法可以避免它.

I am aware of the ideas raised in this question and this one. Here I am most interested in this specific problem, and if there is some way to avoid it.

任何见解都会受到赞赏.

Any insights would be appreciated.

推荐答案

您不能在同一项目中使用不同的STL实现.这意味着即使是同一编译器的不同版本.如果您的LibA具有接受std :: vector作为参数的函数,则只允许从构建LibA的STL传递矢量对象.这就是为什么许多C ++库只公开C API的原因.

You can't use different STL implementation in the same project. This means even different versions from the same compiler. If your LibA has a function that accepts std::vector as an argument you are only allowed to pass vector object from STL that LibA was built with. This is why many C++ libraries expose only C API.

要么更改API,要么使用同一编译器重建所有项目.

Either you change your API or you rebuild all your projects using the same compiler.

您正在做不该做的事情.您处在行为不确定的世界中.尝试调试此特定崩溃没有任何意义.即使您设法使这条线正常工作,也会在其他地方发生新的崩溃.

You are doing something that you shouldn't. You are in the world of undefined behavior. There is no point in trying to debug this particular crash. Even if you managed to make this line work you would get a new crash somewhere else.

这篇关于混合来自不同版本的Visual Studio的库时的运行时问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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