[SOLVED] 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


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" .

Answered By – Richard Barber

Answer Checked By – David Marino (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *