结算采集程序IDEPinf,C++源文件编译顺序的问题

来源:互联网 发布:12年伤感网络歌曲大全 编辑:程序博客网 时间:2024/06/03 15:57
结算采集程序IDEPinf

vector<CGatherEntity> g_vecGatherEntity;
m_GatherDao->ReadGatherInfo()
{
CGatherEntity gatherEntity;


g_vecGatherEntity.clear();g_vecGatherEntity.size:0 g_vecGatherEntity.capacity:0
g_vecGatherEntity.reserve(20);g_vecGatherEntity.size:11539302 g_vecGatherEntity.capacity:20

g_vecGatherEntity.resize(20);加入执行会core dump


g_vecGatherEntity.push_back(gatherEntity);执行会core dump
}


解决问题的思路:
1、自己写了一个程序,只做m_GatherDao->ReadGatherInfo();发现程序正常

2、在原有工程项目中,main() 函数也只做 m_GatherDao->ReadGatherInfo();程序core dump 


3、剪裁程序去掉m_GatherDao->ReadGatherInfo();不涉及的所有.cpp 和.h程序正常


4、试着添加一个个.cpp .h 由于全局变量的关系,在编译过程中的报错,结果所有的.cpp 和.h 都一次性加进来了。程序正常


5、想了想,把编译顺序还原,然后把core dump 的vector<CGatherEntity> g_vecGatherEntity;的.cpp 编译顺序前移程序正常

判断问题:
1、是.cpp程序编译顺序的问题,导致程序core dump (程序中太多了全局变量,依赖关系复杂)。
2、因为g_vecGatherEntity 是全局变量,其他.cpp也会用到这个,是不是编译顺序的调整,是不是会改变变量的定义位置,当这个.cpp在后面编译,会导致其他程序在使用这个变量的时候,还没定义,程序core dump.???


错误顺序: 后面发现其实只要IDEPinf_CGatherDao.cpp 放到前面几个就不会core dump.
SRCS=CException.cpp comm_tool.cpp IDEPinf_CommTool.cpp IDEPinf_CBizFileCheck.cpp IDEPinf_CBizGather.cpp IDEPinf_CBizFindDupBill.cpp IDEPinf_CMainBusinessProcess.cpp IDEPinf_CFileDao.cpp IDEPinf_CGatherDao.cpp IDEPinf_CLogDao.cpp IDEPinf_FuncDef.cpp IDEPinf_main.cpp msg_tool.cpp OcciDataBase.cpp 


正常顺序:
SRCS=CException.cpp comm_tool.cpp IDEPinf_CommTool.cpp IDEPinf_CGatherDao.cpp IDEPinf_main.cpp msg_tool.cpp OcciDataBase.cpp IDEPinf_CMainBusinessProcess.cpp IDEPinf_CBizFileCheck.cpp IDEPinf_CLogDao.cpp IDEPinf_CBizFindDupBill.cpp IDEPinf_CFileDao.cpp IDEPinf_FuncDef.cpp IDEPinf_CBizGather.cpp

阅读全文
0 0