4

I am running macOS High Sierra (10.13.2) and Qt 5.10.0. I would like to use OpenMP with my application.

I have added the following flags to my .pro file

QMAKE_CXXFLAGS += -fopenmp
QMAKE_LFLAGS += -fopenmp
LIBS += -fopenmp

The default compilers on macOS do not contain OpenMP. I installed gcc through homebrew which does support OpenMP.

Under the Build & Run -> Compilers tab of Qt Creator, I added the homebrew g++ and gcc compilers (/usr/local/Cellar/gcc/7.2.0/bin/{gcc-7,g++-7}). I then selected the kit that I am using and changed the compiler to be the homebrew installed compiler that I added under the compilers tab.

If I inspect the Makefile generated by Qt Creator after setting this kit and rebuilding the project, I find the CC and CXX are not using the compiler that I have specified. Here are their values in the Makefile:

CC            = /Library/Developer/CommandLineTools/usr/bin/clang
CXX           = /Library/Developer/CommandLineTools/usr/bin/clang++

These should be /usr/local/Cellar/gcc/7.2.0/bin/g++-7 and /usr/local/Cellar/gcc/7.2.0/bin/gcc-7.

The compiler output that I get now is:

18:14:48: Starting: "/usr/bin/make"

/usr/local/Cellar/qt/5.10.0/bin/qmake -o Makefile ../Practice/Practice.pro -spec macx-g++ CONFIG+=debug CONFIG+=x86_64 CONFIG+=qml_debug

/Library/Developer/CommandLineTools/usr/bin/g++ -c -pipe -fopenmp -g -std=gnu++11 -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk -mmacosx-version-min=10.10 -Wall -W -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I../Practice -I. -I/usr/local/Cellar/qt/5.10.0/lib/QtQuick.framework/Headers -I/usr/local/Cellar/qt/5.10.0/lib/QtGui.framework/Headers -I/usr/local/Cellar/qt/5.10.0/lib/QtQml.framework/Headers -I/usr/local/Cellar/qt/5.10.0/lib/QtNetwork.framework/Headers -I/usr/local/Cellar/qt/5.10.0/lib/QtCore.framework/Headers -I. -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/AGL.framework/Headers -I/usr/local/Cellar/qt/5.10.0/mkspecs/macx-g++ -F/usr/local/Cellar/qt/5.10.0/lib -o main.o ../Practice/main.cpp

clang: error: unsupported option '-fopenmp'

make: *** [main.o] Error 1

18:14:49: The process "/usr/bin/make" exited with code 2.

Error while building/deploying project Practice (kit: Desktop) When executing step "Make"

Why is the Makefile generated by Qt Creator not using the compiler that I am specifying in the kit that I am using?

K. Shores
  • 875
  • 1
  • 18
  • 46

1 Answers1

4

Because the mkspec macx-g++ you're using will override CC and CXX settings. As a temporary workaround, try setting them in the pro file directly:

QMAKE_CC = /usr/local/Cellar/gcc/7.2.0/bin/gcc-7
QMAKE_CXX = /usr/local/Cellar/gcc/7.2.0/bin/g++-7

You may want to edit the mkspec (or making a new one) for your kit and set those variables there.

To find the mkspec file (qmake.conf):

INSTALLDIR=`qmake -query QT_INSTALL_CONFIGURATION`
MKSPECNAME=`qmake -query QMAKE_SPEC`
cd $INSTALLDIR/mkspecs/$MKSPECNAME

As to why you have to set the compilers twice: Qt Creator is meant to be a generic c++ IDE, thus able to manage non-Qt projects, which don't use qmake but need a compiler anyway.

p-a-o-l-o
  • 9,807
  • 2
  • 22
  • 35