Compilation error when building shared library under MAC OS



  • Hello,

    I've created a little shared library using Qt Creator under linux (ubuntu 14.04 LTS).
    It works well and I got all the .so .so1 & co associated files.

    I now want to do the same but from a Mac OS (Sierra). I copyed my source and adapted the .pro files and try to compile.
    I got the following error at build : constexpr constructor never produces a constant expression [-Winvalid-constexpr]
    related to qatomic.h file (linked from qglobal.h) and specifically to QAtomicInt : public QAtomicInteger<int> class.

    Point is I do not especially deal with this class. currently, creating a new empty shared library produces exactly the same error at build.

    Any help to solve this strange behaviour would be appreciated.

    Many thanks

    PS : sorry but I do not know how to copy file or source code in my post...


  • Moderators

    @TBIGNON That sounds like a warning not an error. You are definitely going to have to post a build log for us to solve this for you.

    To post, just copy and paste the output from the log into a post here and you can surround it by 3 backticks, the key left of the 1 on your keyboard. Put 3 to start, paste your output then 3 to end.

    Also what version of Qt are you using on OSX? Was it built from source or installed as binaries?



  • @ambershark
    Thanks for the info. Hereafter the copy of the Compile Output window
    I'm using Qt 5.7.0 installed with the traditionnal setup (no compilation of any sources on my side)

    Thanks again

    09:17:49: Starting: "/Users/eldim-apple/Qt/5.7/clang_64/bin/qmake" /Users/eldim-apple/EmptySharedLibrary/EmptySharedLibrary.pro -spec macx-clang CONFIG+=debug CONFIG+=x86_64 CONFIG+=qml_debug
    Info: creating stash file /Users/eldim-apple/build-EmptySharedLibrary-Desktop_Qt_5_7_0_clang_64bit-Debug/.qmake.stash
    09:17:51: The process "/Users/eldim-apple/Qt/5.7/clang_64/bin/qmake" exited normally.
    09:17:51: Starting: "/usr/bin/make" qmake_all
    make: Nothing to be done for `qmake_all'.
    09:17:52: The process "/usr/bin/make" exited normally.
    09:17:52: Starting: "/usr/bin/make" 
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -g -std=gnu++11 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.8 -Wall -W -fPIC -DEMPTYSHAREDLIBRARY_LIBRARY -DQT_QML_DEBUG -DQT_CORE_LIB -I../EmptySharedLibrary -I. -I../Qt/5.7/clang_64/lib/QtCore.framework/Headers -I. -I../Qt/5.7/clang_64/mkspecs/macx-clang -F/Users/eldim-apple/Qt/5.7/clang_64/lib -o emptysharedlibrary.o ../EmptySharedLibrary/emptysharedlibrary.cpp
    In file included from ../EmptySharedLibrary/emptysharedlibrary.cpp:1:
    In file included from ../EmptySharedLibrary/emptysharedlibrary.h:4:
    In file included from ../EmptySharedLibrary/emptysharedlibrary_global.h:4:
    In file included from /Users/eldim-apple/Qt/5.7/clang_64/lib/QtCore.framework/Headers/qglobal.h:1145:
    /Users/eldim-apple/Qt/5.7/clang_64/lib/QtCore.framework/Headers/qatomic.h:162:5: error: constexpr constructor never produces a constant expression [-Winvalid-constexpr]
        QAtomicInt(int value = 0) Q_DECL_NOTHROW : QAtomicInteger<int>(value) {}
        ^
    /Users/eldim-apple/Qt/5.7/clang_64/lib/QtCore.framework/Headers/qatomic.h:162:48: note: non-literal type 'QAtomicInteger<int>' cannot be used in a constant expression
        QAtomicInt(int value = 0) Q_DECL_NOTHROW : QAtomicInteger<int>(value) {}
                                                   ^
    1 error generated.
    make: *** [emptysharedlibrary.o] Error 1
    09:17:52: The process "/usr/bin/make" exited with code 2.
    Error while building/deploying project EmptySharedLibrary (kit: Desktop Qt 5.7.0 clang 64bit)
    When executing step "Make"
    09:17:52: Elapsed time: 00:03.

  • Moderators

    @TBIGNON Ok so I did a little research and found this is a problem with Qt5.7 and the newest clang from apple.

    I would file a bug with Qt giving your version of clang.

    An easy fix is to use Qt 5.6 on OSX for now as it doesn't have this issue. A less easy but still quite doable fix is to compile Qt 5.7 from source and fix the problem in QAtomicInt before compiling.

    I have had to do this in the past with Qt and OSX since clang is pretty aggressive in it's interpretation of C++11/14 standards. My issue was related to a Qt bug where they used a reserved keyword as a variable name. The keyword was only reserved in clang and no other compilers. It was an easy fix before recompiling source, but this may be more trouble than you want to go through. So I would just downgrade to 5.6 in the meantime while the bug gets addressed.



  • @ambershark

    Thanks for the feedback. I downgraded to Qt5.6.2 but still have the exact same issue.
    I will try with older version but shouldn't it be linked to clang version instead?
    Or should I have to use an older version of Mac OS?
    I'm sorry but I'm really newby on Mac OS...

    Regards



  • OK, I finally got it.
    Issue was indeed related to version of clang.
    I had installed XCode 8.1 but there were still XCode 5.0 features remainnig that were interacting with Qt...
    After uninstalling XCode 5.0 properly, a new error message appeared at compiling that I quickly solved with a little googling (pb with the qdevice.pri file => http://stackoverflow.com/questions/25940368/qt5-target-conditionals-not-found)

    Thanks again for the support


  • Moderators

    @TBIGNON said in Compilation error when building shared library under MAC OS:

    OK, I finally got it.
    Issue was indeed related to version of clang.
    I had installed XCode 8.1 but there were still XCode 5.0 features remainnig that were interacting with Qt...
    After uninstalling XCode 5.0 properly, a new error message appeared at compiling that I quickly solved with a little googling (pb with the qdevice.pri file => http://stackoverflow.com/questions/25940368/qt5-target-conditionals-not-found)

    Thanks again for the support

    No problem, glad it is sorted out. Apple does that kind of stuff a lot with clang. I have problems here and there that require me to patch Qt source before I build it during some clang releases. Usually the Qt team will fix stuff though but sometimes I need cutting edge.

    In your case it sounds like it was the reverse of the typical problem and you had a compiler that was too old instead of too new. :)


Log in to reply
 

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