码迷,mamicode.com
首页 > 编程语言 > 详细

c++全局对象引起程序core dump

时间:2020-04-08 12:14:18      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:ret   core dump   退出   相同   shared   cpp   col   同名   -shared   

当多个动态库中包含相同名字的全局对象时,会在exit的钩子多次注册,当程序退出时对象会析构多次,造成崩溃。

简单的例子:  
aaa.cpp  :

#include <string>
std::string msg("fdsafasfsa");

ccc.cpp:

int main(int argc,char* argv[]){
    return 0;
}

然后

$g++ -g -shared -o libaaa.so aaa.cpp
$g++ -g -shared -o libbbb.so aaa.cpp
$g++ -g -o ccc ccc.cpp -laaa -lbbb -L.
生成的ccc程序,执行就会core dump。

c++全局对象引起程序core dump

标签:ret   core dump   退出   相同   shared   cpp   col   同名   -shared   

原文地址:https://www.cnblogs.com/gelare/p/12658699.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!