C++ stdout is NULL in Multithreaded program

3

I've created project using CMake in VS. Later I've add boost and gmock usage. GMock forced me to set /MT flag on all project in solution (main exe, plugins, dll, UT). Now I'm facing strange problem. Log4Qt is my logging library. During startup when loggers are created deep inside this library

mpTextStream = new QTextStream(stdout);

where 'stdout' during runtime goes to

/* These functions are for enabling STATIC_CPPLIB functionality */
_CRTIMP FILE * __cdecl __iob_func(void)
{
    return _iob;
}

which returns NULL (only first item in this _iob array isn't NULL). Ok, I see that those entries seems to be valid as initialization of this table is

FILE _iob[_IOB_ENTRIES] = {
        /* _ptr, _cnt, _base,  _flag, _file, _charbuf, _bufsiz */

        /* stdin (_iob[0]) */

        { _bufin, 0, _bufin, _IOREAD | _IOYOURBUF, 0, 0, _INTERNAL_BUFSIZ },

        /* stdout (_iob[1]) */

        { NULL, 0, NULL, _IOWRT, 1, 0, 0 },
...

So in the result when

void __cdecl _lock_file (
        FILE *pf
        )
{
        /*
         * The way the FILE (pointed to by pf) is locked depends on whether
         * it is part of _iob[] or not
         */
        if ( (pf >= _iob) && (pf <= (&_iob[_IOB_ENTRIES-1])) )
        {
            /*
             * FILE lies in _iob[] so the lock lies in _locktable[].
             */
            _lock( _STREAM_LOCKS + (int)(pf - _iob) );
            /* We set _IOLOCKED to indicate we locked the stream */
            pf->_flag |= _IOLOCKED;
        }
        else
            /*
             * Not part of _iob[]. Therefore, *pf is a _FILEX and the
             * lock field of the struct is an initialized critical
             * section.
             */
            EnterCriticalSection( &(((_FILEX *)pf)->lock) );
}

stdout isn't recognized as part of _iob array and standard EnterCriticalSection is run which result in 'Unhandled exception at 0x77E58DC9 (ntdll.dll) in ComputerConfShop.exe: 0xC0000005: Access violation writing location 0x00000014.' Should I add some specific building flag? Or gmock can be easily change from /MT to /MD library? Or something other?

c++
cmake
gmock
asked on Stack Overflow Apr 30, 2013 by T4ng10r • edited Dec 11, 2017 by Cœur

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0