If I specify -std=c++0x to g++, then I can't #include <iostream>. I get the following error messages (g++ 4.4.0 under mingw):
In file included from c:\qt\2010.05\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/postypes.h:42,
from c:\qt\2010.05\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/iosfwd:42,
from c:\qt\2010.05\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/ios:39,
from c:\qt\2010.05\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/ostream:40,
from c:\qt\2010.05\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/iostream:40,
from f.cpp:1:
c:\qt\2010.05\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cwchar:159: error: '::swprintf' has not been declared
c:\qt\2010.05\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cwchar:166: error: '::vswprintf' has not been declared
Any ideas why? Has this been fixed in the latest g++? (And if so, does anybody know how to incorporate the latest g++ into Qt?)
It seems to be a bug. There is a thread with a simple patch (in the very end).
if win32{
QMAKE_CXXFLAGS += -std=gnu++0x
}
else {
QMAKE_CXXFLAGS += -std=c++0x
}
Related
I'm on Manjaro Linux with clang++ 9.0.1.
I'm testing std::optional in C++17. When I compile without -stdlib=libc++, the test cpp file compiles without error. However, if I specify -stdlib=libc++, clang++ shows the following error:
$ clang++ -std=c++17 --stdlib=libc++ test.cpp
test.cpp:4:10: fatal error: 'optional' file not found
#include <optional>
^~~~~~~~~~
1 error generated.
Could you please tell me what I should do if I need to compile it with -stdlib=libc++? Thanks in advance!
Thanks to #nathanoliver and #rian-quinn. I find myself so stupid -- I haven't installed libc++. The error got solved by sudo pacman -S libc++.
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
In C++, I am trying to declare an unordered_set simply like this:
std::unordered_set<int> k;
But it is showing this error:
error: 'unordered_set' is not a member of 'std'
I am using g++ (GCC) 5.3.0 on windows using MinGW. Here are the things that I have already considered:
Adding the header file by #include <unordered_set>
Upgrading MinGW
Using the flag -std=gnu++11. (This is not generating any executable or error, not sure if it doing anything or not)
How to fix it and compile my code successfully?
Use -std=c++11 switch and specify output file.
g++ -std=c++11 your_file.cpp -o your_program
I am running into issues compiling Linux-bound applications in Cygwin.
This error:
error: ‘EOF’ was not declared in this scope
is produced by the following code snippet
if (option == EOF) break;
Compiling this in CentOS directly produces no errors.
These are the g++ params passed by the make file:
-g -O0 -Wall -Wextra -std=gnu++11
GCC version on centOS:
4.8.1 20130715
GCC version in Cygwin
4.8.2
I am wondering if I am just missing some libraries in Cygwin, or if this is just a limitation of Cygwin and can't be resolved.
EOF is defined in stdio.h / cstdio. What is likely happening is that you aren't including one of those headers, but are including, for example, iostream. Standard library headers are permitted to cause other headers to get included as well, and some implementations' iostream headers do exactly this, but not all. You shouldn't rely on it. If you use EOF, add an explicit include for the appropriate header in your own code. (Even if it isn't your code, which it isn't in this case, the modification required in the source code is the same.)
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).