Menu

Python.h must be the first included header

Help
tom
2018-01-12
2018-04-09
  • tom

    tom - 2018-01-12

    I'm encountering some problems in building pytohnqt for macosx:

    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -O2 -std=gnu++11  -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -mmacosx-version-min=10.10 -Wall -W -fPIC -DPYTHONQT_CATCH_ALL_EXCEPTIONS -DPYTHONQT_EXPORTS -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -I/System/Library/Frameworks/Python.framework/Headers -I. -I/usr/local/Cellar/qt/5.10.0_1/lib/QtWidgets.framework/Headers -I/usr/local/Cellar/qt/5.10.0_1/lib/QtGui.framework/Headers -I/usr/local/Cellar/qt/5.10.0_1/lib/QtCore.framework/Headers/5.10.0 -I/usr/local/Cellar/qt/5.10.0_1/lib/QtCore.framework/Headers/5.10.0/QtCore -I/usr/local/Cellar/qt/5.10.0_1/lib/QtCore.framework/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/AGL.framework/Headers -I/usr/local/Cellar/qt/5.10.0_1/mkspecs/macx-clang -F/usr/local/Cellar/qt/5.10.0_1/lib -o PythonQtMethodInfo.o PythonQtMethodInfo.cpp
    In file included from PythonQtMethodInfo.cpp:43:
    In file included from ./PythonQtClassInfo.h:36:
    In file included from ./PythonQt.h:59:
    In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iostream:38:
    In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ios:216:
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__locale:478:15: error: C++ requires a type specifier for all declarations
        char_type toupper(char_type __c) const
                  ^
    /System/Library/Frameworks/Python.framework/Headers/pyport.h:731:29: note: expanded from macro 'toupper'
    #define toupper(c) towupper(btowc(c))
                                ^
    
    [...]
    

    This is due to the fact that sometimes QT headers are included before Python.
    This is not recommended (quoting https://docs.python.org/2/c-api/intro.html) "Since Python may define some pre-processor definitions which affect the standard headers on some systems, you must include Python.h before any standard headers are included."

    To be able to build on macosx, 2 headers need to be swapped in src/PythonQtClassInfo.h and src/PythonQtMethodInfo.cpp

    Here is the patch to the current trunk

    Index: src/PythonQtClassInfo.h
    ===================================================================
    --- src/PythonQtClassInfo.h (revision 465)
    +++ src/PythonQtClassInfo.h (working copy)
    @@ -33,12 +33,12 @@
      *
      */
    
    +#include "PythonQt.h"
     #include <QMetaObject>
     #include <QMetaMethod>
     #include <QHash>
     #include <QByteArray>
     #include <QList>
    -#include "PythonQt.h"
    
     class PythonQtSlotInfo;
     class PythonQtClassInfo;
    Index: src/PythonQtMethodInfo.cpp
    ===================================================================
    --- src/PythonQtMethodInfo.cpp  (revision 465)
    +++ src/PythonQtMethodInfo.cpp  (working copy)
    @@ -39,8 +39,8 @@
     */
     //----------------------------------------------------------------------------------
    
    +#include "PythonQtClassInfo.h"
     #include "PythonQtMethodInfo.h"
    -#include "PythonQtClassInfo.h"
     #include <iostream>
    
     QHash<QByteArray, PythonQtMethodInfo*> PythonQtMethodInfo::_cachedSignatures;
    
     
  • Florian Link

    Florian Link - 2018-04-06

    I will have a look, you post was stuck in the admin moderation.
    Strange fact: the code builds on MacOs on our servers...

     
  • Florian Link

    Florian Link - 2018-04-09

    I cleaned that up and commited on svn trunk.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.