C++0x with Qt Creator - c++

I'm trying to use new C++0x features in Qt Creator under Windows (Qt Creator 2.0.1).
I read the thread Configuring the GCC compiler switches in Qt, Qt Creator, and QMake and added QMAKE_CXXFLAGS += -std=c++0x to .pro file.
After it Qt Creator gives me very strange errors on this simple code:
#include <memory>
int main()
{
}
Compiler errors:
'::swprintf' has not been declared
'::vswprintf' has not been declared
I try to compile my code from the command line with command g++ test.cpp --std=c++0x and get same error.
So what's wrong with Qt MinGW compiler? Is it possible to use C++0x features in Qt Creator?

First off, it could be that the library headers just don't represent their dependencies properly. Try adding an #include <cstdio> and perhaps (unfortunately) a using namespace std; to your file at the top.
Failing that, several people seem to have had issues with MinGW and swprintf. This mailing list post suggests adding this:
#ifdef WIN32
#define swprintf _snwprintf
#endif
See if that resolves the issue. (You want it at the very top of the file, too.)
If prepending random defines to your source seems like a bad idea to you, I suggest using -D build flags to conditionally inject the above define when you're building on MinGW.
See also this short discussion on the differences between swprintf on MinGW vs. other compilers.
Finally, failing all else, this link seems to attribute the problem to an issue with flags that enable __STRICT_ANSI__ in MinGW, and suggests commenting out a couple of lines in one of the MinGW headers to fix the issue. I would suggest adding a simpler #ifndef __STRICT_ANSI__ around them instead if you decide to go with this hack.

Related

How do I add GNUstep compiler(s) to Qt creator to have them compile .mm files on Windows?

I have a MacOS project that needs to compile on Windows. I've been using win32-clang-msvc compiler which seems to be the only included compiler that supports objective-c compilation. However, my files have #import statements that that compiler does not support and are using some MacOS libraries/frameworks (like foundation).
I've installed GNUstep msys, core and devel components, but I have no idea what is all the data I need to enter into Qt add compiler menu to have it actually work. Do I use c++.exe or cpp.exe? Do I use gcc.exe? Where is the make path? How to write a mkspec for it?
Is there any documentation on that for GNUstep?
You can add custom compilers in Qt using the QMAKE_EXTRA_COMPILERS variable.
We’ve used this method to support building Objective-C sources on Android using GNUstep. You can check out the example project, which contains an objc-gnustep.pri file with the compiler definition for Objective-C sources. This should similarly work on Windows as well.
That being said I am not sure your setup using Clang and GNUstep MSYS packages will work as-is, as the GNUstep MSYS packages/libraries are probably built with GCC using MinGW libraries, whereas you would be using Clang with the MSVC runtime libraries. GCC comes with an Objective-C runtime, but using Objective-C with Clang requires the external libobjc2 runtime, which currently doesn’t seem to be compatible with MinGW as recently discussed on the mailing list. That being said I’d love to know if you can get it to work.
For the time being, instead of using Clang your best option might be using GCC from MinGW with the GNUstep packages, but note that this doesn’t support Automatic Reference Counting (ARC) and some other features only supported by Clang/libobjc2.

qmake auto-generated Makefile compiler set incorrectly

We are doing a C++ project for our uni and its final phase is passing the whole thing into a graphical interface using Qt.
We use Qt5.4 and g++-5. These values have been set in the QtCreator project configuration by selecting the appropriate compiler, g++-5, and also adding options in the *.pro file such as -std=c++14 and so on.
Nevertheless we are being stumped by an important issue. No matter what we try, when running qmake so as to auto-generate the precompiled files, in any Makefile generated by it, the compiler is ALWAYS set to g++ and not g++-5. We are at the moment obliged to after using qmake having to change by hand the compiler in the Makefile on our own, even though we have told it EVERYWHERE that we are using g++-5 and not the normal g++.
We have tried solutions like in this question: Using c++14
And also changing the compiler in the mkspecs of the Qt SDK.
Both have been to no avail and we still can't get the auto-generated Makefile to use g++-5 unless we change it by hand.
Is this a Qt issue or are we doing a step incorrectly?
Thanks in advance.
Sorry for all the bother.
It is solved now, I had linked my g++ compiler to g++-5 when I installed it ages ago but had forgotten (both g++ and g++-5 work on my pc, but they are the same) so it wasn't being an error, just my pc configuration getting in the way, thanks for the help though.

Qt4 + CGAL - Parse error at "BOOST_JOIN"

I'm getting the error Parse error at "BOOST_JOIN" while trying to compile a code with Qt4 and CGAL. I'm not using Boost directly and I've already searched and tried a bunch of options like -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDEDand -DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION. The versions I'm working with are CGAL 4.1.0, Qt 4.8.4_6 and Boost 1.53.0_1, and using CMake to generate the Makefile, in a machine Mac OS 10.8.2. Any ideas of what could be causing that error?
This problem happens in Boost 1.56.0 with QT 4.7.4 (which is quite old now),
Regardless, another quick workaround is to edit the problematic boost header files,
and
add to the top:
#ifndef Q_MOC_RUN
add to the bottom:
#endif
This will at least let MOC run without dying.
When you compile a piece of code that defines Qt objects, the build system needs to call the Qt Meta Object Compiler, aka "moc". In Qt versions before 5.0, the "moc" compiler (actually a precompiler) does not parse correctly all C++ code. In particular, it does not fully expand preprocessor macros. In recent Boost versions, some macros (like that BOOST_JOIN) are sometimes used to define a namespace name. For example:
namespace BOOST_JOIN(BOOST_TT_TRAIT_NAME,_impl) {
in boost/type_traits/detail/has_binary_operator.hpp of Boost version 1.53.
A Qt bug has being filled at Qt-Project.org and is said to be fixed in Qt-5.0.
In CGAL-4.2, I have tried to suppress those build errors by separating more the use of Qt and Boost in different compilation units. You should retry with a recent version of Boost, and CGAL-4.2-beta1 (or later versions if they are released when you read that answer). Let me know if you encounter similar problems with CGAL-4.2-beta1 or later.
As for Qt-5.0, I hope CGAL-4.3 will support it. We will have to work on the CMake scripts to support it. It will be added to the planning of the next CGAL developers meeting.
I downgraded to Boost 1.52, and now it's compiling.

How to compile c++11 code with android ndk and eclipse?

I'm using android NDK r8d, and eclipse Juno. I'm trying to compile C++ code which uses C++11 stuff like mutex, lock_guard, shared_ptr, etc. in a native android project in eclipse.
I get errors like:
"error: 'shared_ptr' is not a member of 'std'"
"fatal error: mutex: No such file or directory"
I came across a similar question here. It seems to work for them, but the explanation there is not complete so I can't get it to work for me.
I added "NDK_TOOLCHAIN_VERSION=4.7" to the Application.mk and "LOCAL_CFLAGS += -std=c++11" to Android.mk file. Still, it doesn't compile.
In the link above it says:
"Be sure that the standard library include path (like
/android-ndk-r8d/sources/cxx-stl/gnu-libstdc++/4.7/include) is in the
target settings."
How and where do I insert it?
I also get errors in eclipse IDE (on the source, before compiling). I know I should define "__GXX_EXPERIMENTAL_CXX0X__" to resolve them but I just don't know where to put it.
So, if someone could post an answer with a full explanation of how to compile and make eclipse work with C++11 it would be great.
Regarding your first question:
Go to Project > Properties > C/C++ General / Paths and Symbols
In the "Includes" tab, add the proper directory, e.g.
/android-ndk-r8d/sources/cxx-stl/gnu-libstdc++/4.7/include
Regarding your second question, I'm also looking for an answer. It is absolutely not clear how to define the GXX_EXPERIMENTAL_CXX0X macro in Eclipse.
Some say that it should be "added as a predefined macro to the indexer", but it looks like we both could not find a way to implement that...
I have read elsewhere that it should be added to "C/C++ General / Paths and Symbols / Symbols / GNU C++" but I can't find the "Symbols / GNU C++" part in my version of Indigo.
I find export an environment variable NDK_TOOLCHAIN_VERSION=4.8 before i start eclipse can solve this problem.
Eclipse use ndk's default toolchain version 4.6, if NDK_TOOLCHAIN_VERSION is not define, and gcc witch this version does not support all c++11's future like multithread and so on.

Compilation QT Creator project using classic terminal and gcc/g++

I'm tired searching in internet.
I created a klient-serwer program, which shut down computer just by their IP's on specific port.I made whole thing in C, everything works perfectly, i'm compiling my project using gcc with -Wall option and I've got a clear results.
But I had to create GUI so i decided to use QT Creator IDE, I transfered code from C into C++ and i made GUI. Program works but I have to compile this using g++ with -Wall option.
Thing is, I cannot compile anything.
g++ my_project.cpp -o mypro -Wall
ERROR: fatal error: QMainWindow: directory don't exist (in my native language)
compilation terminated
(same with other source files)
Any ideas?
It's propably very easy, but believe me, I want to compile this and go to sleep. Cheers
Why don't you use qmake? First, you can edit your *.pro file and add any compiler flags you wish (see Mitch's comment). Then, if you execute qmake and then make, it will show you a sequence of compilation commands with proper flags, linker and include paths and so on. After that you can just reproduce that commands manually if your teacher wants so.
The error shows that the compiler is trying to open QMainWindow as if it was a directory (if the translation is correct) or at least failing to locate where the include files for Qt are. You probably need to provide some -I option to hint the compiler as to where the Qt headers are, and make sure that the #include directives are correct in your code.