函数调用跳到错误的函数 [英] Function call jumps to the wrong function

查看:127
本文介绍了函数调用跳到错误的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在vs2008中编译一个c ++静态库,在解决方案中,我也有一个使用lib的启动项目,并且运行良好.

I am compiling a c++ static library in vs2008, and in the solution i also have a startup project that uses the lib, and that works fine.

但是在另一个解决方案中使用lib时,出现运行时检查失败. "ESP的值未在整个函数调用中正确保存" 逐步执行代码,我注意到崩溃之前,函数foo()跳转到bar().有问题的函数只是常规函数,没有函数指针.

But when using the lib in another solution i get an run-time check failure. "The value of ESP was not properly saved across a functioncall" Stepping through the code i noticed a function foo() jumping to bar() instead right before the crash. The functions in question are just regular functions and no function pointers.

任何人都知道可能会发生什么,以及为什么在同一解决方案中使用lib时为何起作用?

Anyone has any clue what might be going on, and why it works when using the lib's from the same solution?

函数(方法)是类的一部分,如果有帮助的话.

edit: the functions (methods) are part of a class, if that helps.

推荐答案

请原谅我在此处声明明显的出血,但是...我已经看到这种事情在对象(.o)和标头出现之前已经发生过很多次了(.h)文件不同步.尤其是在虚拟方法方面.

Forgive me for stating the bleeding obvious here, but... I've seen this sort of thing happen many times before when object (.o) and header (.h) files get out of sync. Especially with respect to virtual methods.

考虑:目标文件是使用标头编译的:

Consider: The object file is compiled with header:

class Foo { virtual void f(); };

但是随后标题更改为:

class Foo { virtual void g(); virtual void f(); };

对于下一个目标文件,编译器对f()在类的vtable中的位置的假设是不正确的.

And for the next object file, the compiler's assumptions about where f() is located in the class's vtable are incorrect.

通常情况下,只需重新编译世界(一切!)即可.

Oftentimes simply recompiling the world (everything!) will help.

这篇关于函数调用跳到错误的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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