因为想用template aliases特性,必须要GCC4.7.
又不想编译源代码,所以按照下面的方法安装。
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.7
sudo apt-get install g++-4.7
如果系统中存在多个版本的GCC,可以在CMake工程的顶层的CMakeLists.txt中配置:
cmake_minimum_required(VERSION 2.8.7)
set(CMAKE_C_COMPILER "/usr/bin/gcc-4.7")
set(CMAKE_CXX_COMPILER "/usr/bin/g++-4.7")
project (sample)
add_subdirectory(src bin)
然后在build目录下执行cmake .. 可以看到:
chenshu@chenshu-beijing:~/work/research/tree/normal_tree/build$ cmake ..
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc-4.7
-- Check for working C compiler: /usr/bin/gcc-4.7 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/g++-4.7
-- Check for working CXX compiler: /usr/bin/g++-4.7 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/chenshu/work/research/tree/normal_tree/build
不过我的方法不是CMake推荐的最佳方法,一共有三种方法可以参考:
http://www.cmake.org/Wiki/CMake_FAQ#Method_3_.28avoid.29:_use_set.28.29
How do I use a different compiler?
[edit] Method 1: use environment variables
For C and C++, set the CC and CXX environment variables. This method is not guaranteed to work for all generators. (Specifically, if you are trying to set Xcode's GCC_VERSION, this method confuses Xcode.)
For example:
CC=gcc-4.2 CXX=/usr/bin/g++-4.2 cmake -G "Your Generator" path/to/your/source
[edit] Method 2: use cmake -D
Set the appropriate CMAKE_FOO_COMPILER variable(s) to a valid compiler name or full path on the command-line using cmake -D.
For example:
cmake -G "Your Generator" -D CMAKE_C_COMPILER=gcc-4.2 -D CMAKE_CXX_COMPILER=g++-4.2 path/to/your/source
[edit] Method 3 (avoid): use set()
Set the appropriate CMAKE_FOO_COMPILER variable(s) to a valid compiler name or full path in a list file using set(). This must be done before any language is set (ie before any project() or enable_language() command).
For example:
set(CMAKE_C_COMPILER "gcc-4.2")
set(CMAKE_CXX_COMPILER "/usr/bin/g++-4.2")
project("YourProjectName")
[edit]
默认C++11是不启用的。在src/CMakeLists.txt文件中加上这行:
SET(CMAKE_CXX_FLAGS "-std=c++11") # Add c++11 functionality
然后运行
cmake ..
make VERBOSE=1
你会看到编译的g++命令后面带上了:
/usr/bin/g++-4.7 -std=c++11
现在成功了,享受C++11吧。
分享到:
相关推荐
Ubuntu12.04 nginx python uwsgi Django安装步骤
Ubuntu 12.04 菜鸟完全使用教程让你用最快的速度熟悉使用Ubuntu 12.04!
Ubuntu12.04菜鸟使用手册合集+Ubuntu标准教程Ubuntu12.04菜鸟使用手册合集+Ubuntu标准教程Ubuntu12.04菜鸟使用手册合集+Ubuntu标准教程Ubuntu12.04菜鸟使用手册合集+Ubuntu标准教程Ubuntu12.04菜鸟使用手册合集+...
libc6 for ubuntu 12.04 所有依赖的库都打包 .
用 VMware 安装 Ubuntu 12.04详细过程图解
Ubuntu 12.04下如何安装MySQL ,我按照这文档,已经成功在ubuntu 12.04安装成功mysql!
最全,最好用 自己试试啊ubuntu12.04 vim 配置
适逢七周岁生日之际,Ubuntu正式推出了第四个LTS长期支持版本,开发代号Precise Pangolin的Ubuntu 12.04在2012年4月26日诞生。这是一个令很多linux爱好者振奋的日子,Ubuntu 12.04 LTS发布势必会掀起新的升级高潮,...
Ubuntu12.04的apt-get搜狐源,直接下载至/etc/apt/下即可,执行apt-get update
Ubuntu12.04下的JDK安装,首先到官网上下载jdk-7u51-linux-x64.tar.gz。
ubuntu12.04 server版本,虚拟机共享宿主机的无线网上网,亲测,有图。
ubuntu12.04安装及配置过程详解
ubuntu12.04下Java开发环境的搭建
详细描述了ubuntu12.04版本的使用,对于linux的详细学习还是要看书
ubuntu12.04 服务器 入门指南,包含有关如何安装和配置各种服务器的信息。
VMWare8.0安装Ubuntu12.04教程,傻瓜式安装教程,很详细
Ubuntu 12.04 菜鸟使用手册(全)
zabbix2.03在ubuntu12.04上的安装(最新)
包括源码包及编译安装文档 已在ubuntu上安装成功
在ubuntu12.04下可以通过这个主题包快速的安装苹果mac主题,我自己也正在用这个主题,分享给大家。