todo: using dll by 'Implicit Linking' or 'Explicit Linking'

本文探讨了一个C++项目中DLL使用弱指针导致的崩溃问题。详细介绍了Parent.dll和Child1.dll之间的依赖关系及资源释放顺序对程序稳定性的影响,并通过隐式链接解决了该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

In my c++ project under windows, I've seen a CRASH!

Why will ~weak_ptr() crash in a dll?


Here is my project:

App.exe
    Parent.dll
        Child1.dll

There is a codes:

Parent.dll
void setSomeInfosToChild() {
    child1 = loadLibrary("child1");
    std::share_ptr<xx> info = std::make_shared<xx>();
    child1.setInfo(info);
}
Child1.dll
void setInfo(std::weak_ptr<xx> info) {
    this->m_info = info;
}
std::weak_ptr<xx> m_info

when m_info was doing destructing method, it crashed!


Here is what I've done so far:

Used VMMAP to see that, when Child1.dll was releasing it's resources, Parent.dll had been released, App.exe can no longer find Parent.dll!

Used Dumpbin.exe to see that, Parent.dll's dependencies had Child1.dll, while App.exe had NOT Parent.dll!


These had driven me to learn about 'Implicit Linking' and 'Explicit Linking' of dll. For details, you could do research yourserf. There is not enough time for me to write here :<


Above, you should have known that the Parent.dll was linked explicitly. But I haven't studied why Parent.dll was released before Child1.dll yet. Therefore,  I tried linking Parent.dll implicitly. And it didn't crash any more.


The study will be continued... Hope that I will have enough time:)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值