C++11 compiler for windows - c++

I was just watching a few videos on Channel9. I found things like lambdas really cool. when I tried to copy the example, it failed. auto didn't work either.
I'm using Nokia's qtcreator which ships with gcc-4.4.0.
I wanted to know which compiler has the fun features implemented so I could play around and learn. I'm not anti MS or anyhting so I don't mind trying Visual Studio if it has those features.

Nearly all C++11 features are implemented in the GCC 4.6.x . A good place to get latest GCC builds (MinGW) is the TDM website - http://tdm-gcc.tdragon.net/download . It should be easy to replace your current GCC with TDM GCC by overwriting files...

A special version of MinGW:
MinGW-Builds gives you everything gcc offers (currently 4.7.2)
That is: Including support for std::thread, std::async, std::future and friends.
As far as I know that's by far the most complete C++11 you can get on Windows.
You just get the MinGW-build binaries here. Unlike other gcc-based installations it supports posix threads, which are currently key to getting the gcc support for C++11 threads and friends working on Windows.
Extract the directory mingw to any location and add the following two paths to your PATH environment variable: (well, change F:\coding ...)
F:\coding\MinGW\bin
F:\coding\MinGW\msys\1.0\bin
Add both, separated by semi colon. You will need to log out or reboot. To verify that you got it right, you can open a command prompt, and write
g++ --version
You should get a response like this, mentioning MinGW-builds:
g++ (Built by MinGW-builds project) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc. ...
I wrote a more complete instruction for getting this going with Eclipse, here: http://scrupulousabstractions.tumblr.com/post/36441490955/eclipse-mingw-builds

For playing around and learning C++11 on Windows, I recommend MinGW Distro by Stephan T. Lavavej. The newest version contains GCC 4.8.2 and Boost 1.55.0.

Take a look at MinGW-w64 if you're looking for a gcc-compatible compiler on Windows that supports a number of C++11 features.
Also if you're just looking for lambas and auto, as well as some other C++11 features like decltype, etc., (again, not as many feature are implemented compared to the latest stable gcc branch) then you can also use the free Visual Studio 2010 Express for C++ on Windows.

See here for an overview of the compilers and the supported C++11 features.

Scott Meyers maintains a webpage here:
C++11FeatureAvailability
The First link on the Webpage is:
Apache Wiki Overview of C++11 Support in Several Compilers is what you should have a look at.It doccuments in detail C++11 features supported by all popular compilers.

The Visual Studio 11 preview also supports lambdas.

Visual Studio 2017 has support in C++11, C++14, & C++17. + some of the Modern C++ "experimental" modules. If you decide on Visual Studio, you set the C++ standard at the project properties. C++11 is by default, but you can set it to C++14, C++17, or latest draft.

As regards g++, C++0x feature support should be detailed here: C++0x/C++11 Support in GCC - GNU Project - Free Software Foundation (FSF)

If you want to test most of the C++11 syntax using a Windows machine you have two options:
Install Cygwin and compile from sources gcc-4.7 (latest snapshot) and clang++ with libstdc++. However it is not guaranteed that this will work.
Safest bet: Install a modern Linux (such as Ubuntu if you are a Linux newbie) in a virtual machine (VirtualBox is a free virtual machine application) and in this virtual machine compile gcc-4.7 and clang++. I was able to successfully compile both of them on Ubuntu 11.10 following the instructions from this website.
Best option, as of 2014, is to use Visual Studio 2013 updated with the latest CTP (this will work even for the Express edition).

Few Min-GW Compilers do not support C++ Version 11 or later. This version is required for thread in OpenCV. So I will suggest using TDM-GCC Compiler instead of MinGW Compiler. Install this compiler and set path C:\TDM-GCC-64\bin to the system's environmental variable.

Related

Am I able to use C++11 in QNX?

I have some cross-platform code with some C++11 features like #include <thread> and others. I will soon be using a QNX 6.6 board, and I'm wondering if my code can compile on it, and which features will be available.
QCC is the official QNX C++ compiler, but I can't find any documentation citing which C++11 features, or even which C++ features in general, it supports. Is this a wrapper around GCC or its own thing? Either way, can I get or compile other compilers on this platform?
From what I know qcc is just using gcc internally. Because of this you can use all functionalities provided by the version of gcc that QNX decided to put into their package.
Judging from the release notes of QNX 6.6 gcc 4.7 is used:
GCC 4.7 tool chain, including support for the Intel Advanced Vector Extensions (AVX)
GDB 7.5
New: Binutils 2.24
Python 2.7.5, as a host-side tool
The release notes provide a link to information about gcc 4.7 but I think this link better shows which specific features are supported. There is too much information on the linked page, because of that I do not copy it. But in essence the link states:
GCC provides experimental support for the 2011 ISO C++ standard. This support can be enabled with the -std=c++11 or -std=gnu++11 compiler option ... GCC's C++11 mode implements much of the C++11 standard produced by the
ISO C++ committee
Whereas #Marged's answer seems to cover absolutely every important aspect of your question, I'd like to add that it is also possible to get more current versions of all GNU dev tools (like gcc, gdb or make..). This is officially provided by the QNX staff for "experimental use only", I guess1. But so far I've had only good experiences with them.
Check out QNX's updated Core Development Tools
(You need to register to the QNX community portal first to open the link)
You would then update your Linux dev system like that:
Get files from here
Binutils
GCC
Extract files into a new folder
(do not extract and overwrite existing folder directly since it might be that symbolic links don't get updated)
that should create the host and the target folder
Copy & paste the new files into the actual QNX folder and overwrite existing files
Optionally: update the config default file's value to the new compiler version
e.g. /../qnx650/host/linux/x86/etc/qcc/gcc/default
make sure 32bit libraries are installed (if not):
$ sudo apt-get install lib32stdc++6
if not installed correctly errors like the following can occur
$ i486-pc-nto-qnx6.5.0-g++: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
1 Official text:"Stable versions of the Core Development Tools are included as part of QNX Momentics. You can download updated versions of these tools currently being developed through this project and benefit from their enhancements earlier!"
The version of gcc that is used by qcc does support much of the C++11 specification. I've used it. Just add -std=c++11 to the compiler line.
I did find one issue with C++11 support on QNX 6.6. This was in July 2014, so things may have changed. The support of vector initialization (std::vector<int> {1,2, 3, 4};) in the C++11 library shipped with QNX 6.6 was broken. Code would compile cleanly, but then fail rather cryptically when run. Again, I don't currently know the current status of this issue, so YMMV.

Which C++11 compilers for Windows support new type traits like "is_nothrow_move_constructible"?

Is there any C++11 compiler for Windows that supports the new C++11 type traits, like is_nothrow_move_constructible?
I was trying to write a container that supported it, only to find that none of my compilers (VC++ 2010, TDM MinGW32 GCC 4.6) support it...
For mingw, I would recommend STL's distro here (gcc 4.7.1). It comes with boost 1.50 also.
There also is mingw-w64 (a fork of the original mingw), I recommend rubenvb's personal builds here. Go to Toolchains targetting Win32 if you want the 32-bit versions. He also has personal builds of clang (clang support on windows is still very buggy. The x64 build will report linker errors so can only be used for better diagnostics, etc.)
STL's distro is very nice, however I find the mingw-w64 to have much better support for the win32 api (I have run into countless problems with the original mingw) and c++11 headers, such as <atomic> which is unsupported in the original mingw. mingw-w64 is much more actively developed (can create 32-bit and 64-bit binaries) and includes support for newer functions from windows vista and up.
For more info on the naming conventions of mingw-w64, see here and the faq.
Visual Studio C++ 2012 Beta supports a lot of C++11 type traits according to the reference. Have a look at the Visual Studio C++ 2012 Documentation However, I could not find is_nothrow_move_constructible documented there. It appears to be supported though.
GCC 4.7 does support is_nothrow_move_constructible you can try it on Windows by installing MinGW Distro.
Not an answer, but I just learned something from looking at the source code of GCC 4.7's type_traits header:
You don't even need is_nothrow_xyz in the first place!
The noexcept operator tells you if an exception throws.
So for these specific type traits, you can use that instead.
(Or at least in theory. Whether your compiler implements it is another matter.)

What tool exists to compile C++2011 code for Windows target?

I created a program in C++2011 that actually uses features of C++2011: mutex, unique_lock, condition_variable, future and async.
I've tested it on Debian Linux 64 bits box, and it compiles and runs like a charm.
Now, I want to compile it for Windows.
I tried Visual C++ Express 2010, but it does not have support for the new features of C++. (The Beta for Visual C++/Studio 2012 only runs on Windows 8.)
I tried cross compiling with mingw-g++ (4.6), but it looks like these new features are not supported for the Windows target. (Although they are supported for g++-4.6 for Linux target).
Is there any (free?) solution as of today to compile a C++2011 program for Windows target?
My (commercial) Just::Thread library provides std::thread, std::mutex and friends for MSVC 2005/2008/2010 and the TDM port of mingw-gcc 4.5/4.6 on Windows. It's not free, though.
Alternatively, look for a build of gcc 4.7 for mingw. Support for the thread library on Windows is supposed to be available out-of-the-box with gcc 4.7, but it's not officially released yet.
I have not tried it yet, but this quote from the project site sounds promising:
"Builds support the following technologies:
OpenMP
LTO
Graphite
std_threads
std_atomics
..."
http://code.google.com/p/mingw-builds/
hope this helps

How can I write cross-platform c++ programs on my mac?

My university professor has given a requirement for us in his c++ class: We must write our programs using the gnu C++ compiler (GCC). I understand that after installing xcode, I get an apple version of gcc. However, this is not fully cross compatible as I understand. So I have tried to install the gnu gcc compiler by using mac ports, but I have been unsuccessful. After doing:
port install gcc47
When I go to the terminal and run:
gcc47 -v
I get "command not found"
When I run:
gcc -v
I get:
gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)
Showing that I am still using apple's version. The part I am not understanding is:
How do I install gcc (the gnu version, not apple's version)
How do I use it with an ide, such as eclipse?
The version of GCC you use (Apple or gnu native) should be irrelevant for you to proceed.
Writing portable C++ has nothing to do with the compiler--outside of ensuring your compiler does it's best to adhere to the C++ standard. Luckily enough, GCC is one of the best C++ compilers out there.
You're not looking to do cross-platform C++ per-se, because true portable C++ is somewhat of a pain to write given the various state of C++ compilers for various systems (for example the CC on VAX/VMS doesn't support templates...). I suspect what you want to do is ensure the code you write on your mac, can be compiled by your prof. As long as GCC can handle it on your mac, it should be fine.
So to your specific questions:
Your first question is unnecessary, as you can use apple's supplied g++ to compile your code.
For your second question, I would highly recommend against using an IDE while trying to learn. IDE's offer some really great time saving features, but they hide some important aspects, that I believe are worth struggling with early in your learning process, and which will help strengthen your C++ skills. And while things have certainly have gotten better, some IDE's were notorious for creating non-portable C++ (ie using void main()).
If you are still set on using Eclipse, or XCode, since it doesn't matter which GCC installation you use, the default setup should work just fine.
I've run into troubles installing gcc47 via ports in the past, but gcc46 went as expected. You may also want to install gcc_select.
From there, you can use gcc_select, or specify the path explicitly in Eclipse's toolchain editor.
Other notes:
If you don't need C++11 features, then Apple's GCC 4.2.1 should work fine. Perhaps you can detail why you can't use it. Basically, Apple's added some extensions to the toolchain in some cases (marked APPLE_ONLY), and you have good control of what options are enabled/disabled.
Recent versions of Clang which ship with Xcode handle C++ well (including some support for C++11). There are some advanced things in GCC that I miss when using Clang, but Clang's current C++ support is really quite good.

C++11 with Xcode on Mac OS X Snow Leopard

I have project that is at times developed on Windows/Visual Studio 2010 and uses some C++11 features and I need to be able to develop/build on Mac OS X. When I tried to build the project with Xcode I got a lot of errors around new C++11 features and checked the gcc version to find it's pretty old (4.2).
It looks like Apple is trying to force developers to pay an unnecessary upgrade to Lion by refusing to allow Xcode 4+ to be downloaded on any other version of Mac OS thus I'm left with Xcode 3.x.
How can I continue to use C++11 on Snow Leopard? Is there a way I can do this and keep Xcode as an IDE?
Update feb.25 2012: There are now a lot of features available for you to work with using the latest clang. Maybe you could target 10.6 if you use language features only. If you need library features, you will need 10.7.
given the present (sept.24.2011) state of the Xcode toolset, it's easiest (IMO) to choose another ide or os if you need c++11 support.
the fork of gcc xcode uses will never support these features. clang is pretty far behind wrt c++11 features (because its c++ implementation is still very new and other compilers have had a few extra years). therefore, the compilers xcode ships with do not presently support enough features for c++11 development, regardless of the version of osx you use.
you can install a newer version of gcc and use another ide fairly easily.
technically, you can also make a plugin for xcode 3 (not officially supported) which invokes another compiler (e.g. a more recent release of gcc). that route has been closed in xc4 (afaik). Update apparently, it's still available in Xc4; see idljarn's comment below.
for many projects, it's easier to just use your mac to boot into linux or windows (or use virtualization).
your final option is intel's compiler, which can be used in xcode and provides a decent amount of c++11 support -- try it with xcode before you buy to see if it fits your needs, plays well with xcode, and supports the c++11 features your team uses.
lastly, i don't think they do this for your upgrade money. they really don't maintain xcode for multiple releases very well - they just expect you to stay with the latest and greatest unless you need backwards compatibility; you just stop upgrading in that case. they invested in and assisted development of clang after gcc's license changed. so yeah... osx has always been very far behind wrt c++11 support because they decided to switch to another (very young) compiler. if you wait for xcode to support c++11, you will have to wait for clang to support it, which can be quite some time.
I just saw this now and I would like to update you on this. LLVM currently shipping with XCode is at version 3 (Source). This current version is very good with supporting C++11. Here is a link to what is supported:
http://clang.llvm.org/cxx_status.html
You can compare this with the current GCC support here:
http://gcc.gnu.org/projects/cxx0x.html
As you can see, Clang is currently not far behind, if it is at all, with features of the new standard being supported. The only thing that I see concerning is the lack of support for concurrency features, but that is the case for most C++11 compilers due to the nature of supporting it.So I hope that this answer is not too late and that you are not deterred. Go get the latest version of Xcode and fire away (If you have not done so already ;) )!