Centos安装GCC 4.8.2和boost 1.54.0

Centos安装GCC 4.8.2和boost 1.54.0。

国外有人做了个脚本bld.sh,用起来很舒服:

$ # Download and install it.
$ mkdir /shared/tools/gcc/4.8.2
$ cd /shared/tools/gcc/4.8.2
$ wget http://projects.joelinoff.com/gcc-4.8.2/bld.sh
$ chmod a+x bld.sh
 
$ # Optionally there is also a very simple Makefile.
$ wget http://projects.joelinoff.com/gcc-4.8.2/Makefile
 
$ # bld.sh doesn't check for packages
$ # This is one that I needed.
$ # if not installed you will see a missing gnu/stabs-32.h error late in the process.
$ sudo yum install -y glibc-devel.i686
<output snipped>
 
$ # I also had to install texinfo, you may have to install others.
$ sudo yum install -y texinfo
<output snipped>
 
$ # You can run bld.sh directly or you can simply type "make" if you downloaded
$ # the Makefile.
$ ./bld.sh 2>&1| tee bld.log
安装大约在1个小时左右,如果网速不快,机子性能又不好的话,不建议折腾下去。

下面是个测试文件:

// Simple test program
#include <iostream>
#include <boost/algorithm/string.hpp>
using namespace std;
using namespace boost;
int main()
{
  string s1(" hello world! ");
  cout << "value      : '" << s1 << "'" <<endl;
 
  to_upper(s1);
  cout << "to_upper() : '" << s1 << "'" <<endl;
 
  trim(s1);
  cout << "trim()     : '" << s1 << "'" <<endl;
 
  return 0;
}
编译链接执行如下:

#!/bin/bash
# This script sets the environment to use the newly installed compiler.
# It compiles, links and runs a small test program.
 
# Setup the environment.
MY_GXX_HOME="/shared/tools/gcc/4.8.2/rtf"
export PATH="${MY_GXX_HOME}/bin:${PATH}"
export LD_LIBRARY_PATH="${MY_GXX_HOME}/lib:${LD_LIBRARY_PATH}"
 
# Compile and link.
g++ -O3 -Wall -o test.exe test.cc
 
# Run.
./test.exe
# Expected output
# value      : ' hello world! '
# to_upper() : ' HELLO WORLD! '
# trim()     : 'HELLO WORLD!'

更多的信息请参考: http://joelinoff.com/blog/?p=1003

你可能感兴趣的:(centos,gcc,boost)