这是我第一次尝试将发布版本与 Visual C++ 2005 一起使用,看起来肯定存在一些差异。
我目前的错误是:
Unhandled exception at 0x6ef7d628 (msvcr80d.dll) in <program_name>:
0xC0000005: Access violation reading location 0x6c2e6769.
我查看了调用堆栈,发现传递给我创建的静态库函数的字符串给出了“Bad Ptr”,我不知道为什么。在调试版本中工作得很好......
这是有问题的行:
int main()
{
static Script luaScript("config.lua");
Script 只是我制作的一个处理 lua 脚本文件的类。它是静态的,因为我希望它是一个单例,这样任何代码都可以访问它。
脚本构造函数:
Script::Script(const string &filename)
{
luaState = lua_open();
scriptFilename = filename; // unhandled exception occurs here; Intellisense
// identifies filename as a <Bad Ptr>
// works perfectly fine in debug
}
我想这可能是因为库也处于 Debug模式,但当我尝试使用 Release 时似乎无法编译它。
fatal error C1010: unexpected end of file while looking for precompiled header.
Did you forget to add '#include "stdafx.h"' to your source?
我对那个文件有点熟悉,但为什么我的静态库的 Release 构建需要它?没有在调试中要求它。
好的,去获取 stdafx.h 文件,然后...一个新的错误出现了!
fatal error C1083: Cannot open precompiled header file:
'Release\Script.pch': No such file or directory
好吧,除了“Visual C++ 2005 到底想让我为 Release 构建做些什么!?”之外,很难找到所有这一切的中心问题。
我希望有人能提供帮助。谢谢。
最佳答案
修复Cannot open precompiled header file"
的#1 方法是清理/重建所有。
之后,我将从发布版本和调试版本之间的差异开始。打开项目文件或在 Visual Studio 中比较项目设置。
在担心 Bad Ptr 问题之前,让库在发布中构建。 Bad Ptr 问题很可能会在您克服该问题后消失。
否则,我唯一看到的另一件事是您传递的是 char[] 而不是 std::string。我不认为这真的是个问题,但我会尝试
string filename = "config.lua";
static Script luaScript(filename);
在尝试了我提到的所有其他方法之后。
关于c++ - 发布构建问题;将 std::string 对象传递给静态库函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6636755/