zoukankan      html  css  js  c++  java
  • 在MFC框架下使用osg报内存泄露的解决办法

    作者:朱金灿
    来源:http://blog.csdn.net/clever101/


            最近正在学习osg,从osgchina网站下下载了osg的debug版本库,具体地址为:


    OpenSceneGraph-2.8.2预编译包(for vs9)下载


            然后建了一个MFC的单文档程序写一些测试代码,调试运行了一下,退出时出现大量的内存泄露:
    ......
    {184} normal block at 0x00FB7510, 24 bytes long.
    Data: < u u u > 10 75 FB 00 10 75 FB 00 10 75 FB 00 CD CD CD CD
    {183} normal block at 0x00FB7150, 896 bytes long.
    Data: < > 00 00 00 00 CD CD CD CD CD CD CD CD CD CD CD CD
    {181} normal block at 0x00FB70A0, 24 bytes long.
    Data: < a > D8 61 15 00 FF FF FF FF 00 00 00 00 00 00 00 00
    {180} normal block at 0x00FB6FE0, 128 bytes long.
    Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    {179} normal block at 0x00FB6F20, 128 bytes long.
    Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    {178} normal block at 0x00FB6E60, 128 bytes long.
    Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    {137} normal block at 0x00FB6D98, 136 bytes long.
    Data: < WC > D8 57 43 10 00 00 00 00 01 00 00 00 00 00 00 00
    {135} normal block at 0x00FB6C58, 64 bytes long.
    Data: <OpenThread v1.2p> 4F 70 65 6E 54 68 72 65 61 64 20 76 31 2E 32 70


            开始我吃了一惊,上网搜了一下,找到了一个解决办法:


    Why does my OSG MFC based application show memory leaks


       这个网页上给出的解决办法是:

    . Goto project settings. In there, make the following changes for theDebug build.
    . General->Use of MFC->Use Standard Windows Libraries.
    . Add _AFXDLL to C/C++->Preprocessor->Preprocessor Definitions.
    . Add mfc80??.lib (in my case it is mfc80ud.lib) as a first dependency or at least before osg libs to Linker->Input->Additional
    Dependencies.


    我按照这个办法一试,出现了一个链接错误:
    1>msvcrtd.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
    1>E:/OSG Play/Debug/osgSdi.exe : fatal error LNK1120: 1 unresolved externals
    1>Build log was saved at "file://e:/OSG Play/osgSdi/Debug/BuildLog.htm"
    1> osgSdi - 2 error(s), 0 warning(s)


           之前我只是添加了附加库mfc90ud.lib,这下我把msvcrtd.lib也加进去了,发现还是有这个错误。于是搜索了一下"error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup",判断可能是使用字符集不当造成的。于是在选项里使用多字节字符集,附加库使用mfc90d.lib。重新编译之后好了,我想是不是因为我的osg的核心库是基于多字节字符集生成而造成这个问题的呢?或许只有用unicode版本的osg库一试才能知道。

         早上起来,想到了一个测试办法,就是建一个单文档程序,采用unicode字符集编译,附加库添加mfc90ud.lib,发现也会出现error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup的错误,但采用多字节字符集没有问题。看来并不是osg库的问题。



  • 相关阅读:
    学习笔记-第八周-PLC梯形图编程
    学习笔记-第六周-学习笔记
    学习笔记-第五周-学习笔记
    学习笔记-第四周-心得体会
    学习笔记-第四周-交流电机选优
    学习笔记-第3周-阅读材料&课本预习
    学习笔记-第3周-电机参数优选
    开发日志
    实时软件控制第四周作业
    实时软件控制第三周作业
  • 原文地址:https://www.cnblogs.com/lanzhi/p/6471029.html
Copyright © 2011-2022 走看看