如何更新到C ++ 11? [英] How to update to C++11?

查看:293
本文介绍了如何更新到C ++ 11?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新编程,所以从来没有经历过语言更新。随着C ++ 11的发布,我想利用所有的新功能,如lambda表达式和线程。我知道我可以使用外部库,但使用本地语言功能将更方便。



我在Mac OS X Snowleopard在Xcode 3.2中使用gcc 4.2.1。 6



我需要做些什么和更新才能开始使用C ++ 11功能?你可以更新到Xcode 4.1(或任何最新的版本,你可以获得的Snow Leopard是),并得到一个新的编译器与几个C + + 11特征。在Stack Overflow上有一些帖子关于在Snow Leopard的Xcode 4.1中更好地支持C ++ 11.

但是即使最新的编译器可以通过Xcode不支持一些C ++ 11功能像lambdas。为了获得最好的C ++ 11支持,您需要安装一个更新的编译器,gcc 4.6或4.7或Clang。



我经常构建最新版本的clang从源。如果你熟悉构建其他开源软件,这不难做到。我使用git repos clang和llvm, http://llvm.org/git/llvm.git http://llvm.org /git/clang.git 。您还可以在其网站上找到有关入门指南: http://clang.llvm.org/get_started.html 。一旦你有clang和llvm的源,它只是 ./ configure&&制作&& sudo make install 。 (您可能希望在安装之前运行测试,因为这是直接从存储库中。 make do make check 在llvm目录中,并且一旦将cd传递给tools / clang并运行 make test 。如果一切正常,则 sudo make install



我不记得Snow Leopard是否包含libc ++,所以你可能需要这样做。 http://libcxx.llvm.org/



一旦完成一切并安装你可以做:

  clang ++ -std = c ++ 11 -stdlib = libc ++ main.cpp& ./a.out 

,你应该得到最好的C ++ 11支持。



clang中的最新补丁真的改善了您可能注意到的新C ++程序员的最后功能的支持。还有一些位和剩余,但从3.1,并且据我所知,ang有每个C ++ 11功能,gcc 4.7或VC ++ 11有更多除此之外。 libc ++在C ++ 11标准库特性IME方面也有最小的差距(虽然我认为VC ++的标准库在它们追踪语言特性时也会相当完整,例如char32_t和char16_t作为本机类型,以便标准的特殊化对于这些类型可以使用)。


I am new to programming, so have never experienced a language update. With the release of C++11, I want to make use of all the new features such as lambda expressions and threads. I know I can do this with external libraries but using native language features would be more convenient.

I am using gcc 4.2.1 on Mac OS X Snowleopard in Xcode 3.2.6

What all do I need to do and update to start using C++11 features?

解决方案

You can update to Xcode 4.1 (or whatever the most recent version you can get for Snow Leopard is) and get a new compiler with a few more C++11 features. There are some posts here on Stack Overflow about getting better support for C++11 in Xcode 4.1 on Snow Leopard.

But even the latest compiler available through Xcode does not support some C++11 features like lambdas. To get the best C++11 support you'll want to install a newer compiler, gcc 4.6 or 4.7, or Clang.

I frequently build the latest version of clang from source. It's not difficult to do if you're familiar with building other open source software. I use the git repos for clang and llvm, http://llvm.org/git/llvm.git and http://llvm.org/git/clang.git. You can also find instructions on their website for getting started: http://clang.llvm.org/get_started.html. Once you have the source for clang and llvm it's just ./configure && make && sudo make install. (you might want to run the tests before installing, since this is directly out of the repository. After make do make check in the llvm directory, and once that passes cd down to tools/clang and run make test. If everything is okay then sudo make install)

I don't remember if Snow Leopard included libc++ or not, so you may need to get that as well. http://libcxx.llvm.org/

Once everything is built and installed you can do:

clang++ -std=c++11 -stdlib=libc++ main.cpp && ./a.out

and you should have just about the best C++11 support around.

Recent patches in clang have really improved support for the last features you're likely to notice as a new C++ programmer. There are still a few bits and pieces left, but as of 3.1, and as far as I'm aware, clang has every C++11 feature that either gcc 4.7 or VC++11 has and more besides. libc++ also has the fewest gaps in terms of C++11 standard library features IME (though I think VC++'s standard library will also be pretty complete once they catch up on language features, e.g. char32_t and char16_t as native types so that the standard's mandated specializations for those types can be used).

这篇关于如何更新到C ++ 11?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆