Build errors in C++/Qt project with 3rd party C library due to gmtime_r() declaration in <pthread.h>



  • Hello,

    I have a C++/Qt project in Windows 7 that uses the C library "libnova". Last time I worked on this project in November, everything built just fine. I use the MinGW compiler. This week, I started working again on this project and upgraded from Qt 5.2.1 to Qt 5.4. Now I can't compile my project because of some funny declarations in <pthread.h>. This header is included by almost anything, be it <QApplication>, <iostream> and others. Reverting back to 5.2.1 didn't help.

    Here's a small example:

    @
    #include <iostream>
    #include <libnova/utility.h>

    int main()
    {
    return 0;
    }
    @

    And this is the compiler output:

    @
    22:12:15: Running steps for project CLibCompileTest...
    22:12:15: Configuration unchanged, skipping qmake step.
    22:12:15: Starting: "C:\Qt\Tools\mingw491_32\bin\mingw32-make.exe"
    C:/Qt/Tools/mingw491_32/bin/mingw32-make -f Makefile.Debug
    mingw32-make[1]: Entering directory 'D:/Andreas/Qt/build-CLibCompileTest-Desktop_Qt_5_4_0_MinGW_32bit-Debug'
    g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\CLibCompileTest -I"......\Libraries\libnova-latest\src" -I"C:\Qt\5.4\mingw491_32\include" -I"C:\Qt\5.4\mingw491_32\include\QtWidgets" -I"C:\Qt\5.4\mingw491_32\include\QtGui" -I"C:\Qt\5.4\mingw491_32\include\QtCore" -I"debug" -I"." -I"C:\Qt\5.4\mingw491_32\mkspecs\win32-g++" -o debug\main.o ..\CLibCompileTest\main.cpp
    In file included from C:/Qt/Tools/mingw491_32/i686-w64-mingw32/include/c++/i686-w64-mingw32/bits/gthr-default.h:35:0,
    from C:/Qt/Tools/mingw491_32/i686-w64-mingw32/include/c++/i686-w64-mingw32/bits/gthr.h:148,
    from C:/Qt/Tools/mingw491_32/i686-w64-mingw32/include/c++/ext/atomicity.h:35,
    from C:/Qt/Tools/mingw491_32/i686-w64-mingw32/include/c++/bits/ios_base.h:39,
    from C:/Qt/Tools/mingw491_32/i686-w64-mingw32/include/c++/ios:42,
    from C:/Qt/Tools/mingw491_32/i686-w64-mingw32/include/c++/ostream:38,
    from C:/Qt/Tools/mingw491_32/i686-w64-mingw32/include/c++/iostream:39,
    from ..\CLibCompileTest\main.cpp:2:
    ......\Libraries\libnova-latest\src/libnova/utility.h:230:12: error: expected unqualified-id before '{' token
    struct tm *gmtime_r (time_t *t, struct tm *gmt);
    ^
    ......\Libraries\libnova-latest\src/libnova/utility.h:230:12: error: expected ')' before '{' token
    ......\Libraries\libnova-latest\src/libnova/utility.h:230:12: error: expected primary-expression before 'struct'
    struct tm *gmtime_r (time_t *t, struct tm *gmt);
    ^
    ......\Libraries\libnova-latest\src/libnova/utility.h:230:12: error: expected '}' before 'struct'
    ......\Libraries\libnova-latest\src/libnova/utility.h:230:12: error: expected constructor, destructor, or type conversion before ';' token
    struct tm *gmtime_r (time_t *t, struct tm *gmt);
    ^
    ......\Libraries\libnova-latest\src/libnova/utility.h:230:12: error: '___tmp_tm' does not name a type
    struct tm *gmtime_r (time_t *t, struct tm *gmt);
    ^
    ......\Libraries\libnova-latest\src/libnova/utility.h:230:12: error: expected unqualified-id before 'if'
    struct tm *gmtime_r (time_t *t, struct tm *gmt);
    ^
    ......\Libraries\libnova-latest\src/libnova/utility.h:230:12: error: '___tmp_tm' does not name a type
    struct tm *gmtime_r (time_t *t, struct tm *gmt);
    ^
    ......\Libraries\libnova-latest\src/libnova/utility.h:230:12: error: expected unqualified-id before ')' token
    struct tm *gmtime_r (time_t *t, struct tm *gmt);
    ^
    In file included from ..\CLibCompileTest\main.cpp:3:0:
    ......\Libraries\libnova-latest\src/libnova/utility.h:258:1: error: expected declaration before '}' token
    };
    ^
    Makefile.Debug:233: recipe for target 'debug/main.o' failed
    mingw32-make[1]: Leaving directory 'D:/Andreas/Qt/build-CLibCompileTest-Desktop_Qt_5_4_0_MinGW_32bit-Debug'
    makefile:34: recipe for target 'debug' failed
    mingw32-make[1]: *** [debug/main.o] Error 1
    mingw32-make: *** [debug] Error 2
    22:12:15: The process "C:\Qt\Tools\mingw491_32\bin\mingw32-make.exe" exited with code 2.
    Error while building/deploying project CLibCompileTest (kit: Desktop Qt 5.4.0 MinGW 32bit)
    When executing step "Make"
    22:12:15: Elapsed time: 00:01.
    @

    As you can see in this output, the header file <libnova/utility.h> declares a gmtime_r() function and it probably is in conflict with the same function, that is declared (first) in <pthread.h> (included via <iostream>). In <pthread>, gmtime_r() is first undef'd, then defined again.
    When I change the order of those two includes, the project builds just fine.

    http://sourceforge.net/p/libnova/libnova/ci/master/tree/src/libnova/utility.h

    Is this supposed to be like this? Because I can't really imagine it.
    How should I handle this? I could insert some #ifndef gmtime_r into <libnova/utility.h> but it rather feels like, MinGW is to blame.

    Any advice?

    Andreas



  • Hi,

    This issue cannot have anything to do with Qt. Probably you have a different MinGW version which ships(???) with a different version of pthread.

    Maybe you should consider #include'ing the libnova header in a namespace so as to prevent the name clash.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.