CRT未构造全局对象问题

CRT未构造全局对象问题

引擎中的每个工程均以静态库方式链接到最后的exe. 代码中包含有静态类成员,第一次运行正常,后面不知什么原因, 这些静态类成员不会被初始化, 在 crtexec.c 的CRT 初始化全局类成员函数

static void __cdecl _initterm (
#endif  /* CRTDLL */
        _PVFV * pfbegin,
        _PVFV * pfend
        )
{
        /*
         * walk the table of function pointers from the bottom up, until
         * the end is encountered.  Do not skip the first entry.  The initial
         * value of pfbegin points to the first valid entry.  Do not try to
         * execute what pfend points to.  Only entries before pfend are valid.
         */
        while ( pfbegin < pfend )
        {
            /*
             * if current table entry is non-NULL, call thru it.
             */
            if ( *pfbegin != NULL )
                (**pfbegin)();
            ++pfbegin;
        }
}

 

 

这个函数会初始化所有链接到exe中的全局函数构造, 跟踪这个地方, 发现,只有1个lib中的能被正确调用,但是出问题的那个lib中所有构造都不能被调用. 尝试调整编译顺序无果

唯一的方法只有修改架构为在winmain内进行构造

如果有这方面调试经验的同学可以回帖,谢谢

你可能感兴趣的:(CRT未构造全局对象问题)