Reputation: 2110
I used Qt 5.7 and gcc 4.9.2. Qt Core module throw Qt requires C++11 support
error.
This page say that
gcc 4.9.2 fails to compile Qt.
So I installed gcc 4.8. I check using below command on terminal :
$ g++ --version
g++ (Ubuntu 4.8.4-1ubuntu15) 4.8.4
My kit uses cmake not qmake. I add TARGET_LINK_LIBRARIES ( xxxx yyyy /usr/bin/c++ -std=c++11
to CMakeLists-txt.
I restart my pc and run my application again. Same error is throwed.
/opt/Qt/5.7/gcc_64/include/QtCore/qbasicatomic.h:61: error: #error "Qt requires C++11 support"
# error "Qt requires C++11 support"
^
How can I solve it?
Upvotes: 6
Views: 15754
Reputation: 9
SOMETIMES, this will not be a configuration issue as mentioned in other answers. In my case, the problem was one file that happened to have been saved with a .CPP extension rather than .cpp. QMake (Qt5) was misidentifying the file and trying to compile it with the C compiler rather than the C++ compiler. The QMake from Qt4 was not exhibiting this issue. Renaming the file fixed the issue.
My comment at the time was "Could this really be that f&%%& simple!!"
Upvotes: 0
Reputation: 6039
If using QtCreator, you can add this to your .pro
file:
CONFIG += c++11
https://wiki.qt.io/How_to_use_C%2B%2B11_in_your_Qt_Projects
Upvotes: 4
Reputation: 197
Its has been a while.
How I finally solve it is indicating in CMakeLists.txt the following line just after project(MyProject)
:
add_compile_options(-std=c++11)
That says to cmake, to create a Makefile that will use c++11 solving issues.
Upvotes: 3
Reputation: 2014
solution for me was (in your .pro file):
QMAKE_CXXFLAGS += -stdlib=libc++
QMAKE_CXXFLAGS += -std=c++11
QMAKE_CXXFLAGS += -mmacosx-version-min=10.7
QMAKE_LFLAGS += -mmacosx-version-min=10.7
Upvotes: 1
Reputation: 1471
Turn c++11 on explicitly:
set(CMAKE_CXX_FLAGS "-std=c++11" CACHE STRING "compile flags" FORCE)
after project(...)
declaration.add_library(MyLib SHARED ${PROJECT_HEADERS} ${PROJECT_SOURCES})
...
set_property(TARGET MyLib PROPERTY CXX_STANDARD 11)
set_property(TARGET MyLib PROPERTY CXX_STANDARD_REQUIRED ON)
Upvotes: 0