Results 1 to 4 of 4

Thread: Confusing syntax errors in C header when compiling Qt project

  1. #1
    Join Date
    Aug 2012
    Posts
    18
    Thanks
    4
    Qt products
    Platforms
    Unix/X11 Windows

    Default Confusing syntax errors in C header when compiling Qt project

    Hello,

    I started working again at a Qt project and upgraded it from Qt 5.2.1 to 5.4. Now I get very confusing compiler errors, when I build this project in Qt Creator. The project uses a C library called "libnova" and the MinGW (GCC 4.9.x) compiler from Qt 5.4 finds one of its header files quite offending. I didn't experience this issue when I last worked on that project. Compiling with Qt 5.3 or 5.2.1 kit yield the same results.
    I am using the latest libnova code, as I contributed some fixes for Windows. I compiled the library (as before) with MinGW via MSYS.

    Here's the compiler output:
    Qt Code:
    1. 23:37:45: Running steps for project pyro...
    2. 23:37:45: Starting: "C:\Qt\Tools\mingw491_32\bin\mingw32-make.exe" clean
    3. C:/Qt/Tools/mingw491_32/bin/mingw32-make -f Makefile.Debug clean
    4. mingw32-make[1]: Entering directory 'D:/Andreas/Qt/build-pyro-Desktop_Qt_5_4_0_MinGW_32bit-Debug'
    5. del debug\moc_mainwindow.cpp debug\moc_pyroengine.cpp debug\moc_imageanalysiswidget.cpp debug\moc_projectlistwidget.cpp debug\moc_skyobjectlistmodel.cpp debug\moc_miniatureoverlay.cpp debug\moc_imageloader.cpp
    6. D:\Andreas\Qt\build-pyro-Desktop_Qt_5_4_0_MinGW_32bit-Debug\debug\moc_mainwindow.cpp konnte nicht gefunden werden
    7. del ui_mainwindow.h ui_imageanalysiswidget.h ui_projectlistwidget.h
    8. del debug\main.o debug\mainwindow.o debug\pyromath.o debug\testcases.o debug\pyroengine.o debug\imageanalysiswidget.o debug\projectlistwidget.o debug\skyobjectlistmodel.o debug\miniatureoverlay.o debug\imageloader.o debug\moc_mainwindow.o debug\moc_pyroengine.o debug\moc_imageanalysiswidget.o debug\moc_projectlistwidget.o debug\moc_skyobjectlistmodel.o debug\moc_miniatureoverlay.o debug\moc_imageloader.o
    9. D:\Andreas\Qt\build-pyro-Desktop_Qt_5_4_0_MinGW_32bit-Debug\debug\main.o konnte nicht gefunden werden
    10. mingw32-make[1]: Leaving directory 'D:/Andreas/Qt/build-pyro-Desktop_Qt_5_4_0_MinGW_32bit-Debug'
    11. C:/Qt/Tools/mingw491_32/bin/mingw32-make -f Makefile.Release clean
    12. mingw32-make[1]: Entering directory 'D:/Andreas/Qt/build-pyro-Desktop_Qt_5_4_0_MinGW_32bit-Debug'
    13. del release\moc_mainwindow.cpp release\moc_pyroengine.cpp release\moc_imageanalysiswidget.cpp release\moc_projectlistwidget.cpp release\moc_skyobjectlistmodel.cpp release\moc_miniatureoverlay.cpp release\moc_imageloader.cpp
    14. D:\Andreas\Qt\build-pyro-Desktop_Qt_5_4_0_MinGW_32bit-Debug\release\moc_mainwindow.cpp konnte nicht gefunden werden
    15. del ui_mainwindow.h ui_imageanalysiswidget.h ui_projectlistwidget.h
    16. D:\Andreas\Qt\build-pyro-Desktop_Qt_5_4_0_MinGW_32bit-Debug\ui_mainwindow.h konnte nicht gefunden werden
    17. del release\main.o release\mainwindow.o release\pyromath.o release\testcases.o release\pyroengine.o release\imageanalysiswidget.o release\projectlistwidget.o release\skyobjectlistmodel.o release\miniatureoverlay.o release\imageloader.o release\moc_mainwindow.o release\moc_pyroengine.o release\moc_imageanalysiswidget.o release\moc_projectlistwidget.o release\moc_skyobjectlistmodel.o release\moc_miniatureoverlay.o release\moc_imageloader.o
    18. D:\Andreas\Qt\build-pyro-Desktop_Qt_5_4_0_MinGW_32bit-Debug\release\main.o konnte nicht gefunden werden
    19. mingw32-make[1]: Leaving directory 'D:/Andreas/Qt/build-pyro-Desktop_Qt_5_4_0_MinGW_32bit-Debug'
    20. 23:37:45: The process "C:\Qt\Tools\mingw491_32\bin\mingw32-make.exe" exited normally.
    21. 23:37:45: Configuration unchanged, skipping qmake step.
    22. 23:37:45: Starting: "C:\Qt\Tools\mingw491_32\bin\mingw32-make.exe"
    23. C:/Qt/Tools/mingw491_32/bin/mingw32-make -f Makefile.Debug
    24. mingw32-make[1]: Entering directory 'D:/Andreas/Qt/build-pyro-Desktop_Qt_5_4_0_MinGW_32bit-Debug'
    25. C:\Qt\5.4\mingw491_32\bin\uic.exe ..\pyro\mainwindow.ui -o ui_mainwindow.h
    26. C:\Qt\5.4\mingw491_32\bin\uic.exe ..\pyro\imageanalysiswidget.ui -o ui_imageanalysiswidget.h
    27. C:\Qt\5.4\mingw491_32\bin\uic.exe ..\pyro\projectlistwidget.ui -o ui_projectlistwidget.h
    28. g++ -c -pipe -fno-keep-inline-dllexport -fopenmp -std=gnu++11 -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\pyro -I"..\..\..\Libraries\libnova-latest\src" -I"..\..\..\Libraries\Eigen3" -I"..\..\..\Libraries\ceres-solver-git\include" -I"..\..\..\Libraries\ceres-solver-git\internal\ceres\miniglog" -I"..\..\..\Libraries\ceres-solver-git\config" -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"." -I"C:\Qt\5.4\mingw491_32\mkspecs\win32-g++" -o debug\main.o ..\pyro\main.cpp
    29. In file included from C:/Qt/Tools/mingw491_32/i686-w64-mingw32/include/c++/i686-w64-mingw32/bits/gthr-default.h:35:0,
    30. from C:/Qt/Tools/mingw491_32/i686-w64-mingw32/include/c++/i686-w64-mingw32/bits/gthr.h:148,
    31. from C:/Qt/Tools/mingw491_32/i686-w64-mingw32/include/c++/ext/atomicity.h:35,
    32. from C:/Qt/Tools/mingw491_32/i686-w64-mingw32/include/c++/bits/basic_string.h:39,
    33. from C:/Qt/Tools/mingw491_32/i686-w64-mingw32/include/c++/string:52,
    34. from C:/Qt/Tools/mingw491_32/i686-w64-mingw32/include/c++/random:40,
    35. from C:/Qt/Tools/mingw491_32/i686-w64-mingw32/include/c++/bits/stl_algo.h:66,
    36. from C:/Qt/Tools/mingw491_32/i686-w64-mingw32/include/c++/algorithm:62,
    37. from C:\Qt\5.4\mingw491_32\include/QtCore/qglobal.h:81,
    38. from C:\Qt\5.4\mingw491_32\include/QtCore/qcoreapplication.h:37,
    39. from C:\Qt\5.4\mingw491_32\include\QtWidgets/qapplication.h:37,
    40. from C:\Qt\5.4\mingw491_32\include\QtWidgets/QApplication:1,
    41. from ..\pyro\main.cpp:1:
    42. ..\..\..\Libraries\libnova-latest\src/libnova/utility.h:230:12: error: expected unqualified-id before '{' token
    43. struct tm *gmtime_r (time_t *t, struct tm *gmt);
    44. ^
    45. ..\..\..\Libraries\libnova-latest\src/libnova/utility.h:230:12: error: expected ')' before '{' token
    46. ..\..\..\Libraries\libnova-latest\src/libnova/utility.h:230:12: error: expected primary-expression before 'struct'
    47. struct tm *gmtime_r (time_t *t, struct tm *gmt);
    48. ^
    49. ..\..\..\Libraries\libnova-latest\src/libnova/utility.h:230:12: error: expected '}' before 'struct'
    50. ..\..\..\Libraries\libnova-latest\src/libnova/utility.h:230:12: error: expected constructor, destructor, or type conversion before ';' token
    51. struct tm *gmtime_r (time_t *t, struct tm *gmt);
    52. ^
    53. ..\..\..\Libraries\libnova-latest\src/libnova/utility.h:230:12: error: '___tmp_tm' does not name a type
    54. struct tm *gmtime_r (time_t *t, struct tm *gmt);
    55. ^
    56. ..\..\..\Libraries\libnova-latest\src/libnova/utility.h:230:12: error: expected unqualified-id before 'if'
    57. struct tm *gmtime_r (time_t *t, struct tm *gmt);
    58. ^
    59. ..\..\..\Libraries\libnova-latest\src/libnova/utility.h:230:12: error: '___tmp_tm' does not name a type
    60. struct tm *gmtime_r (time_t *t, struct tm *gmt);
    61. ^
    62. ..\..\..\Libraries\libnova-latest\src/libnova/utility.h:230:12: error: expected unqualified-id before ')' token
    63. struct tm *gmtime_r (time_t *t, struct tm *gmt);
    64. ^
    65. In file included from ..\..\..\Libraries\libnova-latest\src/libnova/libnova.h:127:0,
    66. from ..\pyro\pyromath.h:6,
    67. from ..\pyro\pyroengine.h:16,
    68. from ..\pyro\mainwindow.h:10,
    69. from ..\pyro\main.cpp:3:
    70. ..\..\..\Libraries\libnova-latest\src/libnova/utility.h:258:1: error: expected declaration before '}' token
    71. };
    72. ^
    73. Makefile.Debug:2583: recipe for target 'debug/main.o' failed
    74. mingw32-make[1]: *** [debug/main.o] Error 1
    75. mingw32-make[1]: Leaving directory 'D:/Andreas/Qt/build-pyro-Desktop_Qt_5_4_0_MinGW_32bit-Debug'
    76. mingw32-make: *** [debug] Error 2
    77. makefile:34: recipe for target 'debug' failed
    78. 23:37:48: The process "C:\Qt\Tools\mingw491_32\bin\mingw32-make.exe" exited with code 2.
    79. Error while building/deploying project pyro (kit: Desktop Qt 5.4.0 MinGW 32bit)
    80. When executing step "Make"
    81. 23:37:48: Elapsed time: 00:03.
    To copy to clipboard, switch view to plain text mode 

    You can see the libnova's header file "utility.h" here: http://sourceforge.net/p/libnova/lib...nova/utility.h

    Honestly, I don't understand the compilers complaints. Most of the error messages do not seem to be related to the line declaring the gmtime_r() function. Can someone help, please?


    Andreas

  2. #2
    Join Date
    Aug 2012
    Posts
    18
    Thanks
    4
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: Confusing syntax errors in C header when compiling Qt project

    Okay, I've got something here.

    The compiler errors are only about those gmtime_r and strtok_r declarations. I just commented out these two declarations in <utility.h> and built my project again. It compiles without errors. Apparently, the C library now defines these two functions.

    Digging a little deeper into <time.h> from the toolchain bundled with Qt, I found this for gmtime_r:
    Qt Code:
    1. #ifndef gmtime_r
    2. #define gmtime_r(_Time,_Tm) ...
    To copy to clipboard, switch view to plain text mode 
    <pthread.h> contains the same thing for strtok_r. Was this added to the C library recently?

  3. #3
    Join Date
    Aug 2012
    Posts
    18
    Thanks
    4
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: Confusing syntax errors in C header when compiling Qt project

    Update:

    This small example can also reproduce these compiler errors:
    Qt Code:
    1. #include <iostream>
    2. #include <libnova/utiltiy.h>
    3.  
    4. int main() { return 0; }
    To copy to clipboard, switch view to plain text mode 
    Errors occure, because <iostream> also includes <pthread.h> somewhere down the road. And <pthread.h> has this funny stuff in it:

    Qt Code:
    1. #undef gmtime_r
    2. #define gmtime_r(_Time,_Tm) ({ struct tm *___tmp_tm; \
    3. pthread_testcancel(); \
    4. ___tmp_tm = gmtime((_Time)); \
    5. if (___tmp_tm) { \
    6. *(_Tm) = *___tmp_tm; \
    7. ___tmp_tm = (_Tm); \
    8. } \
    9. ___tmp_tm; })
    To copy to clipboard, switch view to plain text mode 

    Then comes <libnova/utility.h> and declares:

    Qt Code:
    1. struct tm *gmtime_r (time_t *t, struct tm *gmt);
    To copy to clipboard, switch view to plain text mode 

    When I include <libnova/utility.h> first, it will compile sucessfully. But being forced to include headers in a specific order feels very wrong. At least in this case. And it may not be possible in a very big project.

    Is this a bug in the C library provided with MinGW?
    What's the best way to handle this? For the time being, I could surround the conflicting declaratioin in <libnova/utility.h> with #ifndef...#endif.

    Any advice?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Confusing syntax errors in C header when compiling Qt project

    Quote Originally Posted by antimatter View Post
    Any advice?
    Reverse the order of includes.

    Never touch any header files outside your project, fix problems in your code instead.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 1st December 2013, 20:27
  2. Errors while cross compiling Qt
    By ankit jain in forum Installation and Deployment
    Replies: 0
    Last Post: 13th June 2012, 10:05
  3. confusing compiling error
    By hannesvdc in forum Qt Programming
    Replies: 5
    Last Post: 23rd December 2010, 07:12
  4. Errors after compiling for Win
    By cejohnsonsr in forum Newbie
    Replies: 3
    Last Post: 26th August 2010, 22:31
  5. Strange Errors while compiling (QT Header Files)
    By DrDonut in forum Qt Programming
    Replies: 5
    Last Post: 21st May 2009, 13:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.