{"id":108,"date":"2012-02-02T02:30:07","date_gmt":"2012-02-02T02:30:07","guid":{"rendered":"http:\/\/joelinoff.com\/blog\/?p=108"},"modified":"2026-06-28T17:38:53","modified_gmt":"2026-06-29T00:38:53","slug":"bash-script-to-download-build-and-install-gcc-4-6-2-boost-1-48","status":"publish","type":"post","link":"https:\/\/joelinoff.com\/blog\/?p=108","title":{"rendered":"Bash script to download, build and install gcc 4.6.2 and boost 1.48"},"content":{"rendered":"I recently had to build gcc 4.6.2 on CentOS 5.5 and found it to be quite painful so I put together this script to do all of the work: <a title=\"http:\/\/projects.joelinoff.com\/gcc-4.6.2\/bld.sh.txt\" href=\"http:\/\/projects.joelinoff.com\/gcc-4.6.2\/bld.sh.txt\">http:\/\/projects.joelinoff.com\/gcc-4.6.2\/bld.sh.txt<\/a>. I am releasing it in text mode so that you can cut-n-paste it from the web page.\n\nThe shell version is also available: <a title=\"http:\/\/projects.joelinoff.com\/gcc-4.6.2\/bld.sh\" href=\"http:\/\/projects.joelinoff.com\/gcc-4.6.2\/bld.sh\">http:\/\/projects.joelinoff.com\/gcc-4.6.2\/bld.sh<\/a> if you want to download it directly using something like wget.\n<!--more-->\n<h2>Disk Space Usage<\/h2>\nBeware that building gcc-4.6.2 and boost-1.48 requires almost 4 GB of disk space. Here is the breakdown:\n\n\n<pre class=\"wp-block-code language-bash\"><code class=\"language-bash\">% du -s -h gcc-4.6.2\/*\n147M    gcc-4.6.2\/archives\n572M    gcc-4.6.2\/rtf\n3.2G    gcc-4.6.2\/src\n% du -s -h gcc-4.6.2\/src\/*\n602M    gcc-4.6.2\/src\/boost_1_48_0\n25M     gcc-4.6.2\/src\/cloog-0.17.0\n2.1G    gcc-4.6.2\/src\/gcc-4.6.2\n22M     gcc-4.6.2\/src\/gmp-5.0.3\n30M     gcc-4.6.2\/src\/libiconv-1.14\n133K    gcc-4.6.2\/src\/LOCAL-TEST\n4.5M    gcc-4.6.2\/src\/mpc-0.9\n14M     gcc-4.6.2\/src\/mpfr-3.1.0\n481M    gcc-4.6.2\/src\/ppl-0.11.2<\/code><\/pre>\n\n\nAfter the build is complete you can delete the archives and src directory trees to reclaim about 3.3GB of disk space.\n\n<h2>Using bld.sh<\/h2>\nHere is how you might use build script described above to install gcc-4.6.2 and boost-1.48 on your system.\n\n\n<pre class=\"wp-block-code language-bash\"><code class=\"language-bash\">#!\/bin\/bash\numask 0\nmkdir -p \/shared\/tools\/gcc\/gcc-4.6.2\ncd \/shared\/tools\/gcc\/gcc-4.6.2\nwget http:\/\/projects.joelinoff.com\/gcc-4.6.2\/bld.sh\nchmod a+x bld.sh\n.\/bld.sh 2&gt;&amp;1 | tee bld.log<\/code><\/pre>\n\n\n<h2>Simple Test Program: x.cc<\/h2>\nIf you want, you can create a simple program like this:\n\n\n<pre class=\"wp-block-code language-c++\"><code class=\"language-c++\">#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\nAnd then compile, link and run it as follows.\n\n\n<pre class=\"wp-block-code language-bash\"><code class=\"language-bash\">#!\/bin\/bash\nGHM=\"\/shared\/tools\/gcc\/gcc-4.6.2\/rtf\"\nGXX=\"${GHM}\/bin\/g++\"   # OR PATH=\"${GHM}\/bin:${PATH}\"\nexport LD_LIBRARY_PATH=\"${GHM}\/lib64\"\n$GXX -O3 -Wall -o x.exe x.cc\n.\/x.exe\n# Expected output\n# value      : ' hello world! '\n# to_upper() : ' HELLO WORLD! '\n# trim()     : 'HELLO WORLD!'<\/code><\/pre>\n\n\n<h2>Final Thoughts<\/h2>\nThis script has been tested on CentOS 5.5 (x86_64). \n\nI am in the process of testing it on Ubuntu 11.10 (x86_64). \n\n<blockquote>UPDATE #1<br>The Ubuntu 11.10 build failed during the stage1 compilation of gcc because it could not find bits\/predefs.h. That file is available under \/usr\/include\/x86_64-linux-gnu so I expect that it would fairly easy to fix this by adding -I\/usr\/include\/x86_64-linux-gnu to the command line using CPPFLAGS. I will try that and post an update.<\/blockquote>\n\nNote that I decided to use the latest version CLooG (0.17.0) so I had to put in a small hack to fix the gcc\/g++ source code. Specifically I had to change LANGUAGE_C to CLOOG_LANGUAGE_C in the &lt;gcc-4.6.2-source&gt;\/gcc\/graphite-clast-to-gimple.c to track the same change in CLooG. This hack is done automatically by the script. I also had to turn off version checking because it specifically requires 0.16.0.\n\nPlease report problems or suggestions via the comments section.\n\nEnjoy!\n","protected":false},"excerpt":{"rendered":"<p>I recently had to build gcc 4.6.2 on CentOS 5.5 and found it to be quite painful so I put together this script to do all of the work: http:\/\/projects.joelinoff.com\/gcc-4.6.2\/bld.sh.txt. I am releasing it in text mode so that you can cut-n-paste it from the web page. The shell version is also available: http:\/\/projects.joelinoff.com\/gcc-4.6.2\/bld.sh if &hellip; <a href=\"https:\/\/joelinoff.com\/blog\/?p=108\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Bash script to download, build and install gcc 4.6.2 and boost 1.48<\/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":[15,5],"tags":[18],"class_list":["post-108","post","type-post","status-publish","format-standard","hentry","category-bash","category-programming","tag-gcc-4-6-2-boost-1-48-gcc-boost"],"_links":{"self":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/108","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=108"}],"version-history":[{"count":44,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/108\/revisions"}],"predecessor-version":[{"id":1805,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/108\/revisions\/1805"}],"wp:attachment":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}