{"id":811,"date":"2012-09-22T16:11:58","date_gmt":"2012-09-22T16:11:58","guid":{"rendered":"http:\/\/joelinoff.com\/blog\/?p=811"},"modified":"2026-06-28T17:38:17","modified_gmt":"2026-06-29T00:38:17","slug":"bash-script-to-install-gcc-4-7-2-and-boost-1-51-0-on-centos-5-5-and-6-3","status":"publish","type":"post","link":"https:\/\/joelinoff.com\/blog\/?p=811","title":{"rendered":"Bash script to install gcc 4.7.2 and boost 1.51.0 on CentOS 5.5+ and 6.3"},"content":{"rendered":"I recently installed gcc 4.7.2 and boost 1.51.0 on CentOS 5.5, 5.8 and 6.3 to take advantage of the improved support for C++-11. It was painful to do manually so I automated the process with this script: <a title=\"http:\/\/projects.joelinoff.com\/gcc-4.7.2\/bld.sh\" href=\"http:\/\/projects.joelinoff.com\/gcc-4.7.2\/bld.sh\">http:\/\/projects.joelinoff.com\/gcc-4.7.2\/bld.sh<\/a>. Hopefully this will make it easier for folks that want to experiment with the latest version of the GNU C++ compiler.\n\n<div style=\"margin-left: 20px; margin-right: 20px; padding: 5px; background: #ffffdb;\">\nIf you are interested in a more recent version, I recently added a <a href=\"http:\/\/joelinoff.com\/blog\/?p=1514\" title=\"post\">post<\/a> that provides a script to install gcc-4.8.3 and boost 1.55.0.\n<\/div>\n<!--more-->\nThis text version is also available so that you can cut-n-paste from a web page: <a title=\"http:\/\/projects.joelinoff.com\/gcc-4.7.2\/bld.sh.txt\" href=\"http:\/\/projects.joelinoff.com\/gcc-4.7.2\/bld.sh.txt\">http:\/\/projects.joelinoff.com\/gcc-4.7.2\/bld.sh.txt<\/a>. \n\n<h2>1 Download and Install It<\/h2>\nHere are the steps to download and install it. Root access is not required unless you need to install support packages.\n\n\n<pre class=\"wp-block-code language-bash\"><code class=\"language-bash\">$ get-platform.sh\nlinux-centos-6.3-x86_64\n$ # Download and install it.\n$ mkdir \/shared\/tools\/gcc\/4.7.2\n$ cd \/shared\/tools\/gcc\/4.7.2\n$ wget http:\/\/projects.joelinoff.com\/gcc-4.7.2\/bld.sh\n$ chmod a+x bld.sh\n$ # configure doesn't check for this,\n$ # if not installed you will see: missing stabs-32.h\n$ sudo yum install -y glibc-devel.i686\n&lt;output snipped&gt;\n$ .\/bld.sh  &amp;&gt;bld.log<\/code><\/pre>\n\n\nThe build process can take a long time depending on the speed of your CPU(s) and disks. On my test systems it took more than 4 hours.\n\nThe rtf (release to field) directory contains the releases for each package.\n\n<h2>2 Use It<\/h2>\nThis section shows how to compile, link and execute a simple program using the newly installed compiler by setting up your environment properly.\n\n\n<pre class=\"wp-block-code language-c++\"><code class=\"language-c++\">\/\/ Simple test program\n#include &lt;iostream&gt;\n#include &lt;boost\/algorithm\/string.hpp&gt;\nusing namespace std;\nusing namespace boost;\nint main()\n{\n  string s1(\" hello world! \");\n  cout &lt;&lt; \"value      : '\" &lt;&lt; s1 &lt;&lt; \"'\" &lt;&lt;endl;\n\n  to_upper(s1);\n  cout &lt;&lt; \"to_upper() : '\" &lt;&lt; s1 &lt;&lt; \"'\" &lt;&lt;endl;\n\n  trim(s1);\n  cout &lt;&lt; \"trim()     : '\" &lt;&lt; s1 &lt;&lt; \"'\" &lt;&lt;endl;\n\n  return 0;\n}<\/code><\/pre>\n\n\nYou compile, link and run it as follows:\n\n\n<pre class=\"wp-block-code language-bash\"><code class=\"language-bash\">#!\/bin\/bash\n# This script sets the environment to use the newly installed compiler.\n# It compiles, links and runs a small test program.\n\n# Setup the environment.\nMY_GXX_HOME=\"\/shared\/tools\/gcc\/4.7.2\/rtf\"\nexport PATH=\"${MY_GXX_HOME}\/bin:${PATH}\"\nexport LD_LIBRARY_PATH=\"${MY_GXX_HOME}\/lib:${LD_LIBRARY_PATH}\"\n\n# Compile and link.\ng++ -O3 -Wall -o test.exe test.cc\n\n# Run.\n.\/test.exe\n# Expected output\n# value      : ' hello world! '\n# to_upper() : ' HELLO WORLD! '\n# trim()     : 'HELLO WORLD!'<\/code><\/pre>\n\n\n<h2>3 Disk Space Requirements<\/h2>\nYou will need about 8GB to download and build all of the packages. Once the build is finished you can reclaim most of the space because the released files only require about 1 GB. Here is the breakdown:\n\n\n<pre class=\"wp-block-code language-bash\"><code class=\"language-bash\">$ cd \/shared\/tools\/gcc\n$ du -s -h 4.7.2\n8.1G    4.7.2\n$ du -s -h 4.7.2\/*\n147M    4.7.2\/archives\n5.3G    4.7.2\/bld\n14M     4.7.2\/bld.log\n16K     4.7.2\/bld.sh\n1.1G    4.7.2\/rtf\n1.7G    4.7.2\/src<\/code><\/pre>\n\n\n<h2>4 Packages<\/h2>\nThis is the list of packages that are installed in the release area.\n\n<table>\n<thead>\n<tr><th>Package<\/th><th>Version<\/th><th>Web Site<\/th><th>Notes<\/th><\/tr>\n<\/thead>\n<tbody>\n<tr>\n  <td>binutils<\/td>\n  <td><div style=\"text-align:right;\">2.22<\/div><\/td>\n  <td><a href=\"http:\/\/ftp.gnu.org\/gnu\/binutils\">http:\/\/ftp.gnu.org\/gnu\/binutils<\/a><\/td>\n  <td>&nbsp;<\/td>\n<\/tr>\n<tr>\n  <td>boost<\/td>\n  <td><div style=\"text-align:right;\">1.51.0<\/div><\/td>\n  <td><a href=\"http:\/\/sourceforge.net\/projects\/boost\/files\/boost\">http:\/\/sourceforge.net\/projects\/boost\/files\/boost<\/a><\/td>\n  <td>&nbsp;<\/td>\n<\/tr>\n<tr>\n  <td>cloog<\/td>\n  <td><div style=\"text-align:right;\">0.17<\/div><\/td>\n  <td><a href=\"http:\/\/www.bastoul.net\/cloog\">http:\/\/www.bastoul.net\/cloog&#8221;>http:\/\/www.bastoul.net\/cloog<\/a><\/td>\n  <td>&nbsp;<\/td>\n<\/tr>\n<tr>\n  <td>gcc<\/td>\n  <td><div style=\"text-align:right;\">4.7.2<\/div><\/td>\n  <td><a href=\"http:\/\/ftp.gnu.org\/gnu\/gcc\">http:\/\/ftp.gnu.org\/gnu\/gcc<\/a><\/td>\n  <td>&nbsp;<\/td>\n<\/tr>\n<tr>\n  <td>gmp<\/td>\n  <td><div style=\"text-align:right;\">5.0.5<\/div><\/td>\n  <td><a href=\"http:\/\/gmplib.org\/\">http:\/\/gmplib.org\/<\/a><\/td>\n  <td>&nbsp;<\/td>\n<\/tr>\n<tr>\n  <td>libiconv<\/td>\n  <td><div style=\"text-align:right;\">1.14<\/div><\/td>\n  <td><a href=\"http:\/\/ftp.gnu.org\/pub\/gnu\/libiconv\">http:\/\/ftp.gnu.org\/pub\/gnu\/libiconv<\/a><\/td>\n  <td>&nbsp;<\/td>\n<\/tr>\n<tr>\n  <td>mpc<\/td>\n  <td><div style=\"text-align:right;\">1.0<\/div><\/td>\n  <td><a href=\"http:\/\/www.multiprecision.org\/mpc\">http:\/\/www.multiprecision.org\/mpc<\/a><\/td>\n  <td>&nbsp;<\/td>\n<\/tr>\n<tr>\n  <td>mpfr<\/td>\n  <td><div style=\"text-align:right;\">3.1.1<\/div><\/td>\n  <td><a href=\"http:\/\/www.mpfr.org\">http:\/\/www.mpfr.org<\/a><\/td>\n  <td>&nbsp;<\/td>\n<\/tr>\n<tr>\n  <td>ppl<\/td>\n  <td><div style=\"text-align:right;\">1.0<\/div><\/td>\n  <td><a href=\"http:\/\/bugseng.com\/products\/ppl\">http:\/\/bugseng.com\/products\/ppl<\/a><\/td>\n  <td>Not recognized by gcc which looks for 0.11 or later.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\n<h2>5 Tested Platforms<\/h2>\nThese are the platforms that I actually tested the installation on.\n\n<table>\n<thead>\n<tr><th>Distro<\/th><th>Version<\/th><th>Arch<\/th><th>Notes<\/th><\/tr>\n<\/thead>\n<tbody>\n<tr>\n  <td>CentOS<\/td>\n  <td><div style=\"text-align:right;\">6.3<\/div><\/td>\n  <td>x86_64<\/td>\n  <td>Had to manually install the glibc_devel.i686 package.<\/td>\n<\/tr>\n<tr>\n  <td>CentOS<\/td>\n  <td><div style=\"text-align:right;\">5.8<\/div><\/td>\n  <td>x86_64<\/td>\n  <td>Worked out of the box.<\/td>\n<\/tr>\n<tr>\n  <td>CentOS<\/td>\n  <td><div style=\"text-align:right;\">5.5<\/div><\/td>\n  <td>x86_64<\/td>\n  <td>Worked out of the box.<\/td>\n<\/tr>\n<tr>\n  <td>CentOS<\/td>\n  <td><div style=\"text-align:right;\">5.2<\/div><\/td>\n  <td>x86_64<\/td>\n  <td>Verified 2012\/09\/26 by <i>quentin<\/i>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\nUnfortunately, I do not have the bandwidth to try to get this to work on other distros but it should be fairly straightforward to port because it does not rely on distro specific package management. \n\nIf you port it to another distro, please send me the changes to that I can incorporate them.\n\nEnjoy!\n","protected":false},"excerpt":{"rendered":"<p>I recently installed gcc 4.7.2 and boost 1.51.0 on CentOS 5.5, 5.8 and 6.3 to take advantage of the improved support for C++-11. It was painful to do manually so I automated the process with this script: http:\/\/projects.joelinoff.com\/gcc-4.7.2\/bld.sh. Hopefully this will make it easier for folks that want to experiment with the latest version of &hellip; <a href=\"https:\/\/joelinoff.com\/blog\/?p=811\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Bash script to install gcc 4.7.2 and boost 1.51.0 on CentOS 5.5+ and 6.3<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5],"tags":[23,22],"class_list":["post-811","post","type-post","status-publish","format-standard","hentry","category-programming","tag-boost-1-51-0","tag-gcc-4-7-2"],"_links":{"self":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/811","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=811"}],"version-history":[{"count":37,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/811\/revisions"}],"predecessor-version":[{"id":1785,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/811\/revisions\/1785"}],"wp:attachment":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}