2

我在以下代码中遇到运行时崩溃并且也无法调试。请查看并让我知道发生了什么。

// CppConsole.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <assert.h> class Test : public std::tr1::enable_shared_from_this<Test> { public: Test():x(0),y(0),z(0){}; int x; float y; double z; };

int _tmain(int argc, _TCHAR* argv[])
{
    std::tr1::shared_ptr<Test> t1(new Test);
    std::tr1::shared_ptr<Test> t2 = t1->shared_from_this();
    return 0;
}

我已经包含了所有标题,并且程序编译正常。这是我得到的错误:

CppConsole.exe - 未找到入口点 程序入口点 ?_Xweak@tr1@std@@YAXXZ 无法在动态链接库 MSVCP90D.dll 中找到

如果我注释掉这一行

std::tr1::shared_ptr t2 = t1->shared_from_this();

该程序运行而不会崩溃。

更新:问题可以暂时关闭。我将尝试安装 VS 功能包并查看程序执行时没有任何崩溃的天气。

4

4 回答 4

2

谷歌搜索(程序入口点?_Xweak),发现:http: //blog.nilretain.org/

编辑:我在 xp-sp3 上的 msvc 2008 上成功构建并运行它,它具有更高版本的 msvcp90d.dll。也许您可以下载并安装 msvc90 的最新 redist-version 并重新构建。

编辑:您的依赖项说缺少某些东西。看一下这个 :

http://answers.yahoo.com/question/index?qid=20090623140325AAInugo

于 2011-01-20T12:43:43.033 回答
1

您需要一个模板参数:

std::tr1::shared_ptr<Test> t1(new Test);
std::tr1::shared_ptr<Test> t2 = t1->shared_from_this();

如果不存在,编译器应该报告错误。(Visual C++ 2010 可以)

于 2011-01-20T07:27:40.847 回答
0

我在使用 M$ Visual Studio 2008 在 M$ Windows SP3 下开发时遇到了这个问题。我尝试并结合了许多我可以在网上找到的提示。无济于事。解决方案很简单,我必须为 M$ Visual Studio 2008 安装 SP1 包!

问题是我的外部 DLL 使用了我不知道的 C++ TR1 函数。没有 SP 的 M$ Visual Studio 2008 没有正确的运行时 DLL。

因此,在尝试任何其他解决方案之前,请先确保您拥有 M$ Visual Studio 2008 的 SP1。

于 2013-09-25T14:30:41.003 回答
0

您的编译器似乎没有链接到具有所需运行时函数的 DLL。例如,如果您将标头添加到包含路径,但未链接到最新版本的 C++ 运行时(检查您的项目设置),或者安装Visual C++ 2008 功能包不起作用,或者您安装了功能包,但随后尝试从 Visual Studio 2005 等编译。

基本上“处理源代码(包括头文件)”步骤工作正常,但“链接所有 DLL”步骤失败。它失败了,因为您链接的运行时没有shared_ptrs 或weak_ptrs 所需的功能。

于 2011-01-20T09:48:40.333 回答