关闭

g++-4.5.2源码构建&c++0x演示

510人阅读 评论(0) 收藏 举报

title - g++-4.5.2 Build & Install & c++0x demo

[1].http://blog.csdn.net/pongba/archive/2007/04/11/1561194.aspx
[2].http://www.bccn.net/Article/kfyy/cjj/jszl/200607/4179.html
[3].http://www2.research.att.com/~bs/C++0xFAQ.html

1. Prerequisites
$sudo apt-get install build-essential
1.1. http://gcc.gnu.org/install/prerequisites.html
~/software/gcc$wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz
~/software/gcc$wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2
~/software/gcc$wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2

1.2. http://gcc.gnu.org/mirrors.html
选择一个可用ftp站点
$wget ftp://gd.tuwien.ac.at/gnu/gcc/releases/gcc-4.5.2/gcc-core-4.5.2.tar.bz2
$wget ftp://gd.tuwien.ac.at/gnu/gcc/releases/gcc-4.5.2/gcc-g++-4.5.2.tar.gz

1.3.解压
~/software/gcc$tar xjf gcc-core-4.5.2.tar.bz2
~/software/gcc$tar xjf gcc-g++-4.5.2.tar.bz2
~/software/gcc$tar xjf gmp-4.3.2.tar.bz2
~/software/gcc$tar xjf mpfr-2.4.2.tar.bz2
~/software/gcc$tar xzf mpc-0.8.1.tar.gz

~/software/gcc$ ll
总计 37448
drwxr-xr-x 23 zhoubo zhoubo     4096 01-11 10:41 gcc-4.5.2
-rw-r--r--  1 zhoubo zhoubo 28241468 01-10 18:49 gcc-core-4.5.2.tar.bz2
-rw-r--r--  1 zhoubo zhoubo  6479975 01-10 18:50 gcc-g++-4.5.2.tar.bz2
drwxr-xr-x 16 zhoubo zhoubo     4096 01-11 10:12 gmp-4.3.2
-rw-r--r--  1 zhoubo zhoubo  1897483 01-11 10:10 gmp-4.3.2.tar.bz2
drwxr-xr-x  5 zhoubo zhoubo     4096 01-11 10:29 mpc-0.8.1
-rw-r--r--  1 zhoubo zhoubo   544950 01-11 10:05 mpc-0.8.1.tar.gz
drwxr-xr-x  7 zhoubo zhoubo    20480 01-11 10:22 mpfr-2.4.2
-rw-r--r--  1 zhoubo zhoubo  1077886 01-11 10:05 mpfr-2.4.2.tar.bz2

2. Build & Install
~/software/gcc/gmp-4.3.2$ ./configure --prefix=/usr
~/software/gcc/gmp-4.3.2$make
~/software/gcc/gmp-4.3.2$sudo make install

~/software/gcc/mpfr-2.4.2$./configure --prefix=/usr
~/software/gcc/mpfr-2.4.2$make
~/software/gcc/mpfr-2.4.2$sudo make install

~/software/gcc/mpc-0.8.1$./configure --prefix=/usr
~/software/gcc/mpc-0.8.1$make
~/software/gcc/mpc-0.8.1$sudo make install

~/software/gcc/gcc-4.5.2$./configure --prefix=/usr
~/software/gcc/gcc-4.5.2$make
~/software/gcc/gcc-4.5.2$sudo make install

3. demo
3.1. democxx0x.cpp
#include <iostream>
#include <memory>
#include <vector>
#include <functional>
#include <tuple>
#include <string>
#include <thread>

using namespace std;

void demo_auto()
{
    cout << "*** demo auto ***" << endl;
    for (auto i = 0; i < 10; ++i)
    {
        std::cout << i << std::endl;
    }

    std::shared_ptr<int> sp(new int(1));
    std::cout << *sp << std::endl;

    std::vector<double> v;
    v.push_back(1.0);
    v.push_back(1.0/2);
    v.push_back(1.0/3);
    for (auto it = v.begin(); it != v.end(); ++it)
    {
        std::cout << *it << std::endl;
    }
}

void demo_lambda()
{
    cout << "*** demo lambda ***" << endl;

    function<int(int)> product;
    product = [&product] (int n) -> int { return n <= 1 ? 1 : n * product(n - 1); };
    cout << "The answer is: " << product(5) << endl;
}

void demo_tuple()
{
    cout << "*** demo tuple ***" << endl;

    tuple<string,int> t2("Kylling",123);
    auto t = make_tuple(string("Herring"),10, 1.23);    // t will be of type tuple<string,int,double>
    string s = get<0>(t);
    int x = get<1>(t);
    double d = get<2>(t);
   
    cout << "get<0>(t2) : " << get<0>(t2) << "/n"
         << "get<1>(t2) : " << get<1>(t2) << "/n"
         << "get<0>(t) : " << s << "/n"
         << "get<1>(t) : " << x << "/n"
         << "get<2>(t) : " << d << "/n"
         << endl;
}

void f()
{
    cout << "f()" << endl;
}

struct F
{
    void operator()()
    {
        cout << "F::operator()" << endl;
    }
};

void demo_thread()
{
    cout << "*** demo thread ***" << endl;
    thread t1{f};
    thread t2{F()};
    t1.join();
    t2.join(); 
}

int main(int argc, char *argv[])
{
    demo_auto();
    demo_lambda();
    demo_tuple();
    demo_thread();
    return 0;
}

3.2. compile
~/test/cpp0x$g++  -Wall -O2 -std=c++0x -pthread -o democxx0x democxx0x.cpp

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:30580次
    • 积分:562
    • 等级:
    • 排名:千里之外
    • 原创:27篇
    • 转载:2篇
    • 译文:0篇
    • 评论:4条
    文章分类
    最新评论