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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章