Ubuntu16.04安装gcc-6系列与安装boost

1.安装gcc-6:

sudo apt-get update && \ 

sudo apt-get install build-essential software-properties-common -y && \ 

sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \ 

sudo apt-get update && \ 

sudo apt-get install gcc-snapshot -y && \ 

sudo apt-get update && \ 

sudo apt-get install gcc-6 g++-6 -y && \ 

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6


如果系统中未安装gcc:

sudo apt-get install gcc-4.8 g++-4.8 -y && \ 

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8;


如果已经安装gcc,将gcc-4.8换成对应的版本号执行(例如5.8版本):

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5.8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5.8;


2.安装 boost:

wget -o http://sourceforge.net/projects/boost/files/boost/1.63.0/boost_1_63_0.tar.gz/download 

tar xzvf boost_1_63_0.tar.gz

cd boost_1_63_0/ 

sudo apt-get update 

sudo apt-get install build-essential g++ python-dev autotools-dev libicu-dev build-essential libbz2-dev libboost-all-dev 

./b2 

sudo ./b2 install


3.验证环境

$ vim test_boost.cpp

#include <boost/version.hpp>

#include <boost/config.hpp>

#include <boost/lexical_cast.hpp>

#include <iostream>


using namespace std;


int main()

{

using boost::lexical_cast;

int a= lexical_cast<int>("123456");

double b = lexical_cast<double>("123.456");

std::cout << a << std::endl;

std::cout << b << std::endl;

return 0;

}


$ g++ -Wall -o test_boost test_boost.cpp

$ ls

test_boost  test_boost.cpp


$ ./test_boost

123456

123.456




2017.3.30   /   热度:4594   /   分类: c++

发表评论:

©地球仪的BLOG  |  Powered by Emlog