智能指针:运行 WinXP-Sp3 的 VS 9 中运行时崩溃

发布于 2024-10-12 22:40:31 字数 1032 浏览 6 评论 0原文

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

// 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;
}

I have include all the headers and the program is compiling fine. This is the error i am getting:

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

如果我注释掉这一行,

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

程序将运行而不会崩溃。

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

I am getting run time crash in the following piece of code and not able to debug also. Please review and let me know what's going on.

// 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;
}


I have include all the headers and the program is compiling fine. This is the error i am getting:

CppConsole.exe - Entry Point Not Found The procedure entry point
?_Xweak@tr1@std@@YAXXZ could not be located in the dynamic link
library MSVCP90D.dll

If I comment out this line

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

the program runs without crashing.

Update: Question can be closed for now. I will try to install VS feature pack and see weather the program executes without any crashes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

等待圉鍢 2024-10-19 22:40:31

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

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

编辑:您的依赖项表示缺少某些内容。看看这个:

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

Googled it (The procedure entry point ?_Xweak),found this : http://blog.nilretain.org/

EDIT : I Build and Run it successfully on my msvc 2008 on xp-sp3 ,which has later version of msvcp90d.dll.
Maybe you can download and install the latest redist-version of msvc90 and rebuild.

EDIT: your dependencies says something is missing. check this out :

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

胡大本事 2024-10-19 22:40:31

您需要一个模板参数:

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

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

You need a template argument:

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

The compiler should report an error if it is not present. (Visual C++ 2010 does)

清浅ˋ旧时光 2024-10-19 22:40:31

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

“处理源代码(包括标头)”步骤工作正常,但“链接所有 DLL”步骤失败。它失败是因为您链接的运行时没有 shared_ptrweak_ptr 所需的函数。

It appears that your compiler is not linking against a DLL with the needed runtime functions. For instance, if you added the headers to your include path, but don't link to the latest version of the C++ runtime (check your project's settings), or installing the Visual C++ 2008 feature pack didn't work, or you installed the feature pack but then tried to compile from Visual Studio 2005, etc.

Basically the "process the source code (including headers)" step is working fine, but the "link all the DLLs" step is failing. And it's failing because the runtime you're linking against doesn't have the needed functions for shared_ptrs or weak_ptrs.

北方的巷 2024-10-19 22:40:31

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

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

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

I had this problem when developing under M$ Windows SP3 with M$ Visual Studio 2008. I tried and combined many hints that I could find on the web. To no avail. The solution was simple, I had to install SP1 pack for M$ Visual Studio 2008!

The thing is that my external DLLs used C++ TR1 functions that I was not aware of. The M$ Visual Studio 2008 without SP does not have the right runtime DLLs.

So, just make sure you have that SP1 for your M$ Visual Studio 2008 first before trying any other solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文