Bearded Beaver
Bearded Beaver

Reputation: 656

build Qt project with openmp on macOS

I have a qmake project developed on windows that uses openmp and I want to build it on macOS. I followed this instruction How to compile with OpenMP in Qt on macOS?

adding the following to my .pro file:

win32: {
    QMAKE_CXXFLAGS+= -fopenmp
    QMAKE_LFLAGS += -fopenmp
}

unix:!macx {
    QMAKE_CXXFLAGS+= -fopenmp
    QMAKE_LFLAGS += -fopenmp
}

macx: {
    QMAKE_CXXFLAGS += -Xpreprocessor -fopenmp -lomp -I/usr/local/include
    QMAKE_LFLAGS += -lomp
    LIBS += -L /usr/local/lib /usr/local/lib/libomp.dylib
}

But I'm getting this error.

Compiler feature detection failure!
The command "/usr/bin/clang++ -stdlib=libc++ -fopenmp -std=gnu++11 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -mmacosx-version-min=10.13 -fPIC -x c++ -E -v - -target x86_64-apple-darwin19.4.0" terminated with exit code 1.
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
clang: error: unsupported option '-fopenmp'

As far as I understand this message I have something missing on my system but I can't figure out what

Upvotes: 0

Views: 433

Answers (2)

Mal
Mal

Reputation: 21

I have found the reason.

Qt creator looks for flags in QMAKE_CXXFLAGS and if -fopenmp is found it automatically uses it when performing the compiler feature detection, which fails because it's missing the
-Xpreprocessor part.

The trick is to add the flags as a whole string, like this:

QMAKE_CXXFLAGS *= "-Xpreprocessor -fopenmp"

Upvotes: 2

Daniele Comelli
Daniele Comelli

Reputation: 11

I don't think there's anything missing. I met this notice after updating Xcode and QtCreator some time ago. Someone reports that simply Xcode no longer supports OpenMP.. which is possible even if I don't know why. Doing a quick test, with a check on basic features like omp_get/set_max_threads and omp parallel, I see that OpenMP is working properly anyway. The only real drawback, however, is that QtCreator can no longer find the standard template library includes. So for example #include is not resolved correctly and autocompletion doesn't work. I don't know why, but I checked it out on two different macs. Currently I'm using Clang 10 (installed by HomeBrew) to bypass this limit.

Upvotes: 1

Related Questions