I'm giving c++ a try again after being away for 7 years. I've downloaded the newly released Qt 5.0 sdk for osx, but I can't get a basic c++11 feature compiled using Qt Creator. The following statement:
auto i = 3;
results in a compilation error:
mainwindow.cpp:19: error: ISO C++ forbids declaration of 'i' with no type
I've google around for similar problems and found suggestions to put
QMAKE_CXXFLAGS += -std=c++11
or
CONFIG += c++11
in the .pro file. Unfortunately without success .The build fails on unrecognized command line options.
I must be doing something wrong. Any suggestions?
Thanks,
Frans
It's looks like Qt Creator for Mac bug.
I fixed it using
QMAKE_CXXFLAGS += -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.7
LIBS += -stdlib=libc++ -mmacosx-version-min=10.7
in .pro file
I don't know if this is still an issue for you.
On my current system (Max OS X Yosemite - Qt 5.4 - QtCreator 3.0 - XCode 6.1.1) this works like a charm:
In .pro file:
macx {
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.7
QMAKE_CXXFLAGS += -mmacosx-version-min=10.7
QMAKE_CFLAGS += -mmacosx-version-min=10.7
QMAKE_MAC_SDK = macosx10.9
}
macx {
QMAKE_CXXFLAGS += -std=c++11 -stdlib=libc++
QMAKE_CFLAGS += -std=c++11 -stdlib=libc++
}
CONFIG += c++11
Make sure you have the latest Mac OS X SDK installed too.
According to the gcc feature list, auto is supported since gcc 4.4through:
g++ -std=c++0x
you could also try the gcc-specific form:
g++ -std=gnu++0x
Maybe, in your case, an additional problem occurs (g++ parameters not correctly promoted to the compiler).
Related
I am using chrono library for calculating elapsed time but I am getting below warning.
warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
I am beginner in C++ and don't know how to add
QMAKE_CXXFLAGS += -std=c++14
Any help would be highly appreciated.
IF you are using a qmake project, it should be
CONFIG += c++14
in the project file as mention in an answer to this post: How can I use C++14 features when building qmake projects
You should add the flags in your compiling command:
g++ -std=c++14 chronoprog.cpp -lmpir -o chronoprog
Although I tried what was suggested in How to enable C++11 in Qt Creator?
this did not work with my Qt Creator using Qt 4.8 in mac os x snow leopard 10.6.8. When compiling with GCC 4.9, adding:
QMAKE_CXXFLAGS += -std=c++11
I get
cc1plus: error: unrecognized command line option "-std=c++11"
Is this meant to be compatible by Qt 4.8 like the link above said? or not?
You can try to force the compiler you want to use in the .pro file:
QMAKE_CC = full path of gcc (for ex. /opt/local/bin/gcc49)
QMAKE_CXX = full path of g++
QMAKE_LINK = full path of g++
QMAKE_LINK_SHLIB_CMD = full path of g++
I am reading the LLVM's Kaleidoscope tutorial (http://llvm.org/docs/tutorial/index.html).
I wanted to compile and test the language. After some compiler's errors (EngineBuilder and Module's constructor, linking libs...), the example program was built. Then, I tried the language. I got a few problems with InitializeNativeTargets, DataLayoutPass... But I managed to correct them.
Howewer, I don't manage to resolve one error. When I write extern printd(x); printd(5);, the program doesn't work : "LLVM ERROR : Program used external function 'printd' which could not be resolved".
I looked for the solution on the net. I read a lot of webpages, but nothing worked.
How can I resolve this problem ? Why LLVM can't find the external function 'printd', which is included in the program ? Thanks in advance for your answer.
The used code : https://docs.google.com/document/d/1Qb-zUGaUUIF354uFCXv1iuq8n_rjya6IHDW4WCPWN_4/edit?usp=sharing
The .pro file (Qt Creator) :
QT += core
QT -= gui
TARGET = Kaleidoscope
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += /home/alainetflo/Documents/me/C++/LLVM/llvm-3.5.0.src/include
DEPENDPATH += /home/alainetflo/Documents/me/C++/LLVM/llvm-3.5.0.src/include
LIBS += `llvm-config --ldflags --libs all --system-libs` -Wl,-no-as-needed
QMAKE_CFLAGS += -m32
QMAKE_CXXFLAGS += -rdynamic -std=c++11 -O3
I use GCC 4.8.2, LLVM 3.5 and Qt 5.3.1 on Ubuntu 14.04 32bits.
Finally, I found a great link on the net : http://koichitamura.blogspot.fr/2011/01/since-i-went-to-held-several-weeks-ago.html.
The error came from the wrong place of the -rdynamic argument in the .pro file (-rdynamic must be after the linking options). You need this argument because (GCC man page) :
This instructs the linker to add all symbols, not only used ones, to the dynamic symbol table.
I changed the .pro file :
QT += core
QT -= gui
TARGET = Test01
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += /home/alainetflo/Documents/me/C++/LLVM/llvm-3.5.0.src/include
DEPENDPATH += /home/alainetflo/Documents/me/C++/LLVM/llvm-3.5.0.src/include
INCLUDEPATH += /usr/include/i386-linux-gnu/c++/4.8 \
/usr/include/c++/4.8
LIBS += `llvm-config --ldflags --libs all --system-libs` -Wl,-no-as-needed -rdynamic
QMAKE_CFLAGS += -m32
QMAKE_CXXFLAGS += -g -std=c++11 -O3
In this way, the program works with no error ! (The tutorial's example runs (http://llvm.org/docs/tutorial/LangImpl6.html#kicking-the-tires))
I have clang++ 3.5, g++ 4.9.1, libc++ and Qt Creator installed on Ubuntu 14.04.1.
I usually use clang++ as compiler. But recently I found that libstdc++ from g++ used as C++ Standard Library. As I know the latter not fully supports C++14 innovations at the moment.
How to replace libstd++ with libc++ when project compiled with clang++?
What I already done (.pro-file):
QMAKE_CXXFLAGS_CXX11 = -std=gnu++1y
CONFIG *= c++11
QMAKE_CXXFLAGS += -stdlib=libc++
LIBS += -stdlib=libc++
But the Qt Creator editor still uses libstdc++ as DEPENDPATH when crawling through included files. How to fix such ill behaviour? Maybe should I fix something in mkspec files?
The standard library is specified in the mkspec files.
In linux, you can use : qmake -spec linux-clang-libc++
I think the equivalent in qtcreator is to define a new "kit" and specify "linux-clang-libc++" in the field "Qt mkspec"
The title is pretty self-descriptive. I've downloaded Qt Creator 2.7.0, and I am trying to compile some basic C++11 code:
int my_array[5] = {1, 2, 3, 4, 5};
for(int &x : my_array)
{
x *= 2;
}
I'm receiving the following error:
range based for loops are not allowed in c++ 98 mode
Yet, according to this article this version of Qt Creator supports C++11. So how do I enable it?
According to this site add
CONFIG += c++11
to your .pro file (see at the bottom of that web page). It requires Qt 5.
The other answers, suggesting
QMAKE_CXXFLAGS += -std=c++11 (or QMAKE_CXXFLAGS += -std=c++0x)
also work with Qt 4.8 and gcc / clang.
Add this to your .pro file
QMAKE_CXXFLAGS += -std=c++11
or
CONFIG += c++11
As an alternative for handling both cases addressed in Ali's excellent answer, I usually add
# With C++11 support
greaterThan(QT_MAJOR_VERSION, 4){
CONFIG += c++11
} else {
QMAKE_CXXFLAGS += -std=c++0x
}
to my project files. This can be handy when you don't really care much about which Qt version is people using in your team, but you want them to have C++11 enabled in any case.
add to your qmake file
QMAKE_CXXFLAGS+= -std=c++11
QMAKE_LFLAGS += -std=c++11
If you are using an earlier version of QT (<5) try this
QMAKE_CXXFLAGS += -std=c++0x
The only place I have successfully make it work is by searching in:
...\Qt\{5.9; or your version}\mingw{53_32; or your
version}\mkspecs\win32-g++\qmake.conf:
Then at the line:
QMAKE_CFLAGS += -fno-keep-inline-dllexport
Edit :
QMAKE_CFLAGS += -fno-keep-inline-dllexport -std=c++11