Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4248084
  • 博文数量: 447
  • 博客积分: 1241
  • 博客等级: 中尉
  • 技术积分: 5786
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-27 06:48
个人简介

读好书,交益友

文章分类

全部博文(447)

文章存档

2024年(1)

2023年(5)

2022年(29)

2021年(49)

2020年(16)

2019年(15)

2018年(23)

2017年(67)

2016年(42)

2015年(51)

2014年(57)

2013年(52)

2012年(35)

2011年(5)

分类: C/C++

2012-09-27 15:35:32

先说说为什么要安装gcc 4.7?
安装gcc 4.7,并不是因为agentzh使用gcc 4.7,是为了准备学习一下c++11.
gcc 支持的特性
 
Language Feature Proposal Available in GCC 4.7?
Rvalue references Yes
Rvalue references for *this No
Initialization of class objects by rvalues Yes
Non-static data member initializers Yes
Variadic templates Yes
Extending variadic template template parameters Yes
Initializer lists Yes
Static assertions Yes
auto-typed variables Yes
Multi-declarator auto Yes
Removal of auto as a storage-class specifier Yes
New function declarator syntax Yes
New wording for C++11 lambdas Yes
Declared type of an expression Yes
Right angle brackets Yes
Default template arguments for function templates Yes
Solving the SFINAE problem for expressions Yes
Template aliases Yes
Extern templates Yes
Null pointer constant Yes
Strongly-typed enums Yes
Forward declarations for enums Yes
Generalized attributes No
Generalized constant expressions Yes
Alignment support No
Delegating constructors Yes
Inheriting constructors No
Explicit conversion operators Yes
New character types Yes
Unicode string literals Yes
Raw string literals Yes
Universal character name literals Yes
User-defined literals Yes
Standard Layout Types Yes
Defaulted and deleted functions Yes
Extended friend declarations Yes
Extending sizeof Yes
Inline namespaces Yes
Unrestricted unions Yes
Local and unnamed types as template arguments Yes
Range-based for Yes
Explicit virtual overrides Yes
Minimal support for garbage collection and reachability-based leak detection No
Allowing move constructors to throw [noexcept] Yes (core language only)
Defining move special member functions Yes
Concurrency
Sequence points No
Atomic operations Yes
Strong Compare and Exchange No
Bidirectional Fences No
Memory model No
Data-dependency ordering: atomics and memory model No
Propagating exceptions Yes
Abandoning a process and at_quick_exit No
Allow atomics use in signal handlers No
Thread-local storage No
Dynamic initialization and destruction with concurrency No
C99 Features in C++11
__func__ predefined identifier Yes
C99 preprocessor Yes
long long Yes
Extended integral types No
Language Feature Proposal Available in GCC 4.7?
Rvalue references Yes
Rvalue references for *this No
Initialization of class objects by rvalues Yes
Non-static data member initializers Yes
Variadic templates Yes
Extending variadic template template parameters Yes
Initializer lists Yes
Static assertions Yes
auto-typed variables Yes
Multi-declarator auto Yes
Removal of auto as a storage-class specifier Yes
New function declarator syntax Yes
New wording for C++11 lambdas Yes
Declared type of an expression Yes
Right angle brackets Yes
Default template arguments for function templates Yes
Solving the SFINAE problem for expressions Yes
Template aliases Yes
Extern templates Yes
Null pointer constant Yes
Strongly-typed enums Yes
Forward declarations for enums Yes
Generalized attributes No
Generalized constant expressions Yes
Alignment support No
Delegating constructors Yes
Inheriting constructors No
Explicit conversion operators Yes
New character types Yes
Unicode string literals Yes
Raw string literals Yes
Universal character name literals Yes
User-defined literals Yes
Standard Layout Types Yes
Defaulted and deleted functions Yes
Extended friend declarations Yes
Extending sizeof Yes
Inline namespaces Yes
Unrestricted unions Yes
Local and unnamed types as template arguments Yes
Range-based for Yes
Explicit virtual overrides Yes
Minimal support for garbage collection and reachability-based leak detection No
Allowing move constructors to throw [noexcept] Yes (core language only)
Defining move special member functions Yes
Concurrency
Sequence points No
Atomic operations Yes
Strong Compare and Exchange No
Bidirectional Fences No
Memory model No
Data-dependency ordering: atomics and memory model No
Propagating exceptions Yes
Abandoning a process and at_quick_exit No
Allow atomics use in signal handlers No
Thread-local storage No
Dynamic initialization and destruction with concurrency No
C99 Features in C++11
__func__ predefined identifier Yes
C99 preprocessor Yes
long long Yes
Extended integral types No

Language Feature

Proposal

Available in GCC 4.7?

Rvalue references

Yes

Rvalue references for *this

No

Initialization of class objects by rvalues

Yes

Non-static data member initializers

Yes

Variadic templates

Yes

Extending variadic template template parameters

Yes

Initializer lists

Yes

Static assertions

Yes

auto-typed variables

Yes

Multi-declarator auto

Yes

Removal of auto as a storage-class specifier

Yes

New function declarator syntax

Yes

New wording for C++11 lambdas

Yes

Declared type of an expression

Yes

Right angle brackets

Yes

Default template arguments for function templates

Yes

Solving the SFINAE problem for expressions

Yes

Template aliases

Yes

Extern templates

Yes

Null pointer constant

Yes

Strongly-typed enums

Yes

Forward declarations for enums

Yes

Generalized attributes

No

Generalized constant expressions

Yes

Alignment support

No

Delegating constructors

Yes

Inheriting constructors

No

Explicit conversion operators

Yes

New character types

Yes

Unicode string literals

Yes

Raw string literals

Yes

Universal character name literals

Yes

User-defined literals

Yes

Standard Layout Types

Yes

Defaulted and deleted functions

Yes

Extended friend declarations

Yes

Extending sizeof

Yes

Inline namespaces

Yes

Unrestricted unions

Yes

Local and unnamed types as template arguments

Yes

Range-based for

Yes

Explicit virtual overrides

Yes

Minimal support for garbage collection and reachability-based leak detection

No

Allowing move constructors to throw [noexcept]

Yes (core language only)

Defining move special member functions

Yes

Concurrency

Sequence points

No

Atomic operations

Yes

Strong Compare and Exchange

No

Bidirectional Fences

No

Memory model

No

Data-dependency ordering: atomics and memory model

No

Propagating exceptions

Yes

Abandoning a process and at_quick_exit

No

Allow atomics use in signal handlers

No

Thread-local storage

No

Dynamic initialization and destruction with concurrency

No

C99 Features in C++11

__func__ predefined identifier

Yes

C99 preprocessor

Yes

long long

Yes

Extended integral types

No

 visual c++ 11支持的特性

VC10 VC11
Rvalue references , , , , v2.0 v2.1*
No No
No No
Variadic templates , No No
No No
Yes Yes
auto , v1.0 v1.0
Yes Yes
Lambdas , , v1.0 v1.1
decltype , v1.0 v1.1**
Yes Yes
No No
No No
No No
Yes Yes
Yes Yes
Partial Yes
No Yes
No No
No No
TR1 Partial
No No
No No
No No
No No
No No
No No
No No
No No
No Yes
No No
Yes Yes
No No
No No
No No
Yes Yes
No Yes
override and final , , Partial Yes
Yes Yes
No No

C++11 Core Language Features: Concurrency VC10 VC11
N/A N/A
No Yes
No Yes
No Yes
N/A N/A
No Yes
No No
Yes Yes
No No
No No
Partial Partial
No No

VC10

VC11

Rvalue references , , , ,

v2.0

v2.1*

No

No

No

No

Variadic templates ,

No

No

No

No

Yes

Yes

auto ,

v1.0

v1.0

Yes

Yes

Lambdas , ,

v1.0

v1.1

decltype ,

v1.0

v1.1**

Yes

Yes

No

No

No

No

No

No

Yes

Yes

Yes

Yes

Partial

Yes

No

Yes

No

No

No

No

TR1

Partial

No

No

No

No

No

No

No

No

No

No

No

No

No

No

No

No

No

Yes

No

No

Yes

Yes

No

No

No

No

No

No

Yes

Yes

No

Yes

override and final , ,

Partial

Yes

Yes

Yes

No

No

 

C++11 Core Language Features: Concurrency

VC10

VC11

N/A

N/A

No

Yes

No

Yes

No

Yes

N/A

N/A

No

Yes

No

No

Yes

Yes

No

No

No

No

Partial

Partial

No

No

 

C++11 Core Language Features: C99

VC10

VC11

Partial

Partial

Partial

Partial

Yes

Yes

N/A

N/A

 

C++11 Core Language Features: C99 VC10 VC11
Partial Partial
Partial Partial
Yes Yes
N/A N/A

不难发现 ,visual c++ 11 支持很不错,但是VS 2012 编译的C++ 程序一直不支持Windows Xp,经过再三选择,决定使用gcc 4.7。

gcc4.7 是最新的gcc,我使用centos 的gcc 这是4.4,必须编译新的版本。

还好有人写出了脚本bld.sh

安装 gcc-4.7.0和boost-1.49

#!/bin/bash
umask 0
mkdir -p /shared/tools/gcc/gcc-4.7.0
cd /shared/tools/gcc/gcc-4.7.0
wget
chmod a+x bld.sh
./bld.sh 2>&1 | tee bld.log

我这里访问国外的网站真慢,下载了一天一夜,其中binutils-2.22.tar.bz2,gmp-5.0.4.tar.bz2,boost_1_49_0.tar.bz2还是手工下载放入archive目录下。

编译过程需要14个小时,占用4G空间,新的gcc 终于可以用了。

测试一

建立文件

vi compile

#!/bin/bash
GHM="/shared/tools/gcc/gcc-4.7.0/rtf"
GXX="${GHM}/bin/g++"   # OR PATH="${GHM}/bin:${PATH}"
export LD_LIBRARY_PATH="${GHM}/lib"
$GXX -O3 -Wall -o x.exe x.cc
./x.exe
# Expected output
# value      : ' hello world! '
# to_upper() : ' HELLO WORLD! '
# trim()     : 'HELLO WORLD!'

这个32位的,64位使用lib64

x.cc

// Test the gcc 4.7.0 compiler.
#include
#include
using namespace std;
using namespace boost;
int main()
{
  string s1(" hello world! ");
  cout << "value      : '" << s1 << "'" <

  to_upper(s1);
  cout << "to_upper() : '" << s1 << "'" <

  trim(s1);
  cout << "trim()     : '" << s1 << "'" <

  return 0;
}

测试一下std thread

vi compile2

GHM="/shared/tools/gcc/gcc-4.7.0/rtf"
GXX="${GHM}/bin/g++"   # OR PATH="${GHM}/bin:${PATH}"
export LD_LIBRARY_PATH="${GHM}/lib"
$GXX -O3 -Wall -std=c++11 -o b.exe b.cc -lpthread
./b.exe

b.cc

#include
#include
        
        void hello(){
            std::cout << "Hello from thread " << std::endl;
        }
        
        int main(){
            std::thread t1(hello);
            t1.join();
        
            return 0;
        }

注意链接的时候 加入pthread,否则会出现

terminate called after throwing an instance of 'std::system_error'

阅读(7624) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~