目录
异常弹窗
- 且有时弹窗后点击中止,程序并不会停止运行
问题定位
- 打断点debug缩小范围,然后发现是一句调用spdlog库生成log文件的代码引发:
- 百度得到了一些解析,这个问题是因为对象在析构时不正确的释放内存导致,且该问题只在使用了动态库才会有
解决办法
- 但spdlog内的代码显然不好去碰,而且这个问题是因为我们链接了spdlog的动态库才会有,那么我们可以使用它的header-only,也就是仅头文件,直接静态编译进入我们的程序,不使用它的动态库了。
- 由于我的项目是用cmake构建,在CMakeLists.txt中,将原来的 spdlog::spdlog 改为 spdlog::spdlog_header_only 即可。
- 然后就发现fmt也来这个问题,我真是吐了
- 那就再加一句,fmt::fmt-header-only 也使用静态编译的方式引入fmt库
最后
- 回顾这个问题,百度上也有博客说应当注意,编译生成动态库应尽量使用 /MD 和 /MDd,避免/MT和/MTd。动态库中避免函数传入参数或返回值使用 std::string 类型,应当使用 std::string& 或 [const] char*。
- 其次,这个问题和编译时的选项有关
- 如果程序和动态库都使用 /MD 编译,则不会有问题
- 如果动态库使用/MT编译,则程序和动态库各自有一个堆,假设我们的程序调用了一个动态库中的一个函数 std::string get(); 而这个string的内存是由动态库分配,但我们的程序并不能区分这个内存是程序的还是动态库的,当对象生命周期结束,就会由程序调用析构函数去释放内存,因此出错。
- 因此解决办法还可以是避免我们的程序去析构动态库返回的string。比如动态库中的函数返回全局变量。
https://pornmaster.fun/hd/xxx-gandi-stories-comnuska-heroine-sexy-chudai-photo-pura
벼룩시장 신문그대로보기 (구인구직, 부동산) 벼룩시장 신문그대로보기 바로가기 그리고 지역별 벼룩시장 종이신문그대로보기 방법 (구인구직, 부동산) 알아볼게요. 교차로신문 같이 벼룩시장은 지역별 일자리, 구인구직, 부동산 등 다양한 정보를 제공해요. 교차로신문그대로보기 바로가기는 아래에서 확인하고, 오늘은 벼룩시장 신문그대로보기 바로가기 그리고 사용법 섹스카지노사이트
I blog quite often and I genuinely thank you for your information. The article has
truly peaked my interest. I will bookmark your site and
keep checking for new details about once a week. I subscribed to your RSS feed too.
What i don’t understood is in reality how you’re not really much
more neatly-favored than you may be now. You’re so intelligent.
You already know thus significantly with regards to this
topic, made me for my part consider it from so many numerous angles.
Its like men and women aren’t fascinated unless it’s one thing to
accomplish with Woman gaga! Your personal stuffs nice. Always take care of
it up!
Heya i am for the first time here. I came across this board and I find It truly useful & it helped me out much.
I hope to give something back and help others like you aided me.
I visited several websites except the audio feature for audio songs current at
this web site is in fact fabulous.
Hurrah, that’s what I was searching for, what a material!
present here at this blog, thanks admin of this
web page.
Hey I know this is off topic but I was wondering if you knew of any
widgets I could add to my blog that automatically tweet my newest twitter updates.
I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would
have some experience with something like this. Please let
me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.
https://itgunza.com/1061