Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't use C++11 features when building with Qt

Tags:

macos

c++11

qt

qt5

I'm on OS X 10.8.4 (Mountain Lion) with the latest command line tools from Xcode. I'm trying to build a Qt project (in Qt Creator) which uses some C++11 features; notably std::unique_ptr. Whenever I try building though, I get the following error:

clang: error: invalid deployment target for -stdlib=libc++ (requires OS X 10.7 or later)

My .pro file is as follows:

QT       += core gui

QMAKE_CXXFLAGS += -mmacosx-version-min=10.7 -std=c++11 -stdlib=libc++
LIBS += -mmacosx-version-min=10.7 -stdlib=libc++

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = APPNAME
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui
cache()

I've tried the solutions presented in other answers (see here and the top answer here), neither of which seemed to work.

like image 371
Lander Avatar asked Jul 28 '13 23:07

Lander


People also ask

Can I use C with Qt?

To use Qt, you must have a C++ compiler. But it doesn't mean that your "application logic" can't be written in C, compiled with a C compiler and carefully linked to the C++ part (the GUI with Qt). This application logic can be generic, linkable into other executables (pure-C, mixed C/C++, etc.)

Is Qt only for C++?

While the Qt framework is C++ based, you can also code with QML and JavaScript. In fact, you can create full apps without even touching C++.

Does Qt support C++ 17?

As mentioned, Qt 6 makes C++17 a requirement in order to adopt its more advanced language features.

Is Qt Creator good for C++?

Qt Creator is a cross-platform (Windows, Linux, Mac) IDE that is part of the Qt SDK and is aimed at simplifying the development of cross-platform GUI applications. It is mostly used with C++ (especially with embedded devices that require UI front), but also with JavaScript and QML.


1 Answers

According to this site add

CONFIG += c++11

to your .pro file (see at the bottom of that web page). It requires Qt 5.


UPDATE: As for Qt 4, see How to enable C++11 in Qt Creator?

like image 83
Ali Avatar answered Oct 05 '22 23:10

Ali