bob_bill
bob_bill

Reputation: 123

How to fix "Qt requires a C++17 compiler" error?

I installed with brew the CGAL C++ library. After doing cmake . in the first basic example , I do make and I got a sequence of errors, the first one and most important is:

/usr/local/include/QtCore/qglobal.h:96:6: error: "Qt requires a C++17 compiler"
#    error "Qt requires a C++17 compiler"
     ^

which means that I need a way to tell Qt to use a C++17 compiler. How can I fix this? I'm an engineer, and I've never faced a similar issue before. There have been similar questions before (like this) but they're about Windows.

I'm using a MacOS BigSur, 11.6.2. and gcc --version returns

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Upvotes: 12

Views: 7554

Answers (2)

Fariman Kashani
Fariman Kashani

Reputation: 1024

I did run cmake -DCMAKE_CXX_COMPILER="gcc" -DCMAKE_CXX_FLAGS="-std=c++17" . to fix this but it didn't help. After spending a day trying to solve this issue, I solved it by removing qt (brew uninstall qt). I had installed both qt and qt@5 and I think CMake was getting confused and picking up some files from qt, and others from qt@5. Hope this help someone.

Upvotes: 13

Richard Barber
Richard Barber

Reputation: 6431

Actually, you will need to tell cmake to activate c++17 support in the compiler commands it generates. By default, Apple clang was chosen, and that comes with an earlier default std support.

cmake -DCMAKE_CXX_FLAGS="-std=c++17" .

If for whatever reason you intended to compile with the gcc wrapper or some other compiler, you can let cmake know:

cmake -DCMAKE_CXX_COMPILER="gcc" -DCMAKE_CXX_FLAGS="-std=c++17" .

Upvotes: 9

Related Questions